Recipe: Delete a Synced Realm from ROS 2.x
Author: Eric Maxwell
Language: REST
Date: November 9, 2017
As you’re developing with the Realm Platform, there may be a time when you want to completely remove a Realm database from your Realm Object Server. This is very easy to do. All it takes is a simple REST call.
Pre-heat your oven
Before deleting the Realm from ROS, make sure that any / all clients (iOS, Android, Js, etc.) has already deleted the app or database locally. If this is not done, they will try to upload their copy of the database - which might have been replaced in the meantime.
Start Baking!
You can delete a Realm in the Realm Object Server by making an HTTP DELETE in the form of http[s]://IP:PORT/realms/files/:realmPath
with realmPath
being the path to the realm such as /<userId>/myRealm
which is URI encoded.
So for example
Let’s say I had a database at the path (in a locally running ROS instance)
/8ec309f8cdbc42e8583d427f0ef91f81/eventblank
An admin token of
eyJhcHBfaWQiOiJpby5yZWFsbS5hdXRoIiwiaWRlbnRpdHkiOiJfX2FkbWluIiwiYWNjZXNzIjpbImRvd25sb2FkIiwidXBsb2FkIiwibWFuYWdlIl0sInNhbHQiOiI1MjYyNTUyMyJ9:ii1TmI40IE4pI2NO7xR/ZDLjq9ufKoRSKf+9yH3RALe+r9hpJxha2f8WBe8TmJgvNwBSlaIfCaH1nK19xirrv8BM9DLfowI25AaK+IXj0ylXD4tqsCpo4UkAagbgWCc/zKpj9YGzQJV22JYKtv5Q7Tdg9GVWev5dWQi/m+JY7tArYaaH46sxOYFsEHKxJ+Oi/KXXZu4KhzcssWf5n4bbgHDICl/CA9gX97r3DxPrn0AVlqKDcVZbAqlEIQhzzgrsoMlhUa9KaTxiXVvAIkS8X0axDtHMAwndNhcKnfJIK7wOg43tbsqcoVQQUoO4X/voDb+FZWnlNNl5mvRnvSDKhw==
I could delete that database using that token by making an HTTP DELETE call to
http://127.0.0.1:9080/realms/files/8ec309f8cdbc42e8583d427f0ef91f81%2Feventblank
## Note the encoded slash in the database path $userId%2Fdatabase
Full example using wget
Erics-MacBook-Pro:~ ericmaxwell$ wget --method DELETE --header 'Authorization: eyJhcHBfaWQiOiJpby5yZWFsbS5hdXRoIiwiaWRlbnRpdHkiOiJfX2FkbWluIiwiYWNjZXNzIjpbImRvd25sb2FkIiwidXBsb2FkIiwibWFuYWdlIl0sInNhbHQiOiI1MjYyNTUyMyJ9:ii1TmI40IE4pI2NO7xR/ZDLjq9ufKoRSKf+9yH3RALe+r9hpJxha2f8WBe8TmJgvNwBSlaIfCaH1nK19xirrv8BM9DLfowI25AaK+IXj0ylXD4tqsCpo4UkAagbgWCc/zKpj9YGzQJV22JYKtv5Q7Tdg9GVWev5dWQi/m+JY7tArYaaH46sxOYFsEHKxJ+Oi/KXXZu4KhzcssWf5n4bbgHDICl/CA9gX97r3DxPrn0AVlqKDcVZbAqlEIQhzzgrsoMlhUa9KaTxiXVvAIkS8X0axDtHMAwndNhcKnfJIK7wOg43tbsqcoVQQUoO4X/voDb+FZWnlNNl5mvRnvSDKhw==' http://127.0.0.1:9080/realms/files/8ec309f8cdbc42e8583d427f0ef91f81%2Feventblank
Output
--2017-11-08 09:17:29-- http://127.0.0.1:9080/realms/files/8ec309f8cdbc42e8583d427f0ef91f81%2Feventblank
Connecting to 127.0.0.1:9080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2 [application/json]
Saving to: ‘8ec309f8cdbc42e8583d427f0ef91f81%2Feventblank’
8ec309f8cdbc42e8583d427f0ef91f81%2Fev 100%[=========================================================================>] 2 --.-KB/s in 0s
2017-11-08 09:17:29 (150 KB/s) - ‘8ec309f8cdbc42e8583d427f0ef91f81%2Feventblank’ saved [2/2]