# Deleting a stream
# Soft deleting
To delete a stream over the Atom interface, issue a DELETE
request to the resource.
curl -X DELETE "http://127.0.0.1:2113/streams/newstream"
HTTP/1.1 204 Stream deleted
Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-Forwarded-Host, X-Forwarded-Prefix, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTos
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ES-Position, ES-CurrentVersion
Content-Type: text/plain; charset=utf-8
Server: Mono-HTTPAPI/1.0
Date: Fri, 27 Jul 2018 11:51:02 GMT
Content-Length: 0
Connection: close
// Make sure to add code blocks to your code group
By default when you delete a stream, EventStoreDB soft deletes it. This means you can recreate it later by setting the $tb
metadata section in the stream. If you try to GET
a soft deleted stream you receive a 404 response:
curl -X GET "http://127.0.0.1:2113/streams/newstream" \
-H 'Accept: application/vnd.eventstore.events+json'
HTTP/1.1 410 Deleted
Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-Forwarded-Host, X-Forwarded-Prefix, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTos
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ES-Position, ES-CurrentVersion
Content-Type: text/plain; charset=utf-8
Server: Mono-HTTPAPI/1.0
Date: Fri, 27 Jul 2018 12:04:10 GMT
Content-Length: 0
Connection: close
// Make sure to add code blocks to your code group
You can recreate the stream by appending new events to it (like creating a new stream):
curl -i -d "@event-append.json" "http://127.0.0.1:2113/streams/newstream" \
-H "Content-Type:application/vnd.eventstore.events+json" \
-H "ES-EventType: SomeEvent"
HTTP/1.1 201 Created
Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-PINGOTHER
Access-Control-Allow-Origin: *
Location: http://127.0.0.1:2113/streams/newstream/1
Content-Type: text/plain; charset: utf-8
Server: Mono-HTTPAPI/1.0
Date: Fri, 28 Jun 2013 12:32:18 GMT
Content-Length: 0
Keep-Alive: timeout=15,max=100
// Make sure to add code blocks to your code group
The version numbers do not start at zero but at where you soft deleted the stream from
# Hard deleting
You can hard delete a stream. To issue a permanent delete use the ES-HardDelete
header.
WARNING
A hard delete is permanent and the stream is not removed during a scavenge. If you hard delete a stream, you cannot recreate the stream.
Issue the DELETE
as before but with the permanent delete header:
curl -X DELETE http://127.0.0.1:2113/streams/newstream -H "ES-HardDelete:true"
HTTP/1.1 204 Stream deleted
Content-Length: 0
Content-Type: text/plain; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-PINGOTHER, Authorization
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location
Date: Thu, 13 Mar 2014 20:56:55 GMT
// Make sure to add code blocks to your code group
The stream is now permanently deleted, and now the response is a 410
.
curl -X GET "http://127.0.0.1:2113/streams/newstream" \
-H 'Accept: application/vnd.eventstore.events+json'
HTTP/1.1 410 Deleted
Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-Forwarded-Host, X-Forwarded-Prefix, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTos
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ES-Position, ES-CurrentVersion
Content-Type: text/plain; charset=utf-8
Server: Mono-HTTPAPI/1.0
Date: Fri, 27 Jul 2018 12:04:10 GMT
Content-Length: 0
Connection: close
// Make sure to add code blocks to your code group
If you try to recreate the stream as in the above example you also receive a 410
response.
curl -i -d "@event-append.json" "http://127.0.0.1:2113/streams/newstream" \
-H "Content-Type:application/vnd.eventstore.events+json" \
-H "ES-EventType: SomeEvent"
curl -i -d "@event-append.json" "http://127.0.0.1:2113/streams/newstream" \
-H "Content-Type:application/vnd.eventstore.events+json" \
-H "ES-EventType: SomeEvent"
// Make sure to add code blocks to your code group