Angular Example

Try it from the command line

The demo database exposes a the messages collection at https://beta.mrest.io without requiring authentication. Access to any other MongoDB resource is forbidden.

mrest.io is an upcoming managed service for RESTHeart.

The demo instance requires an api key, passed via request header key:demo

This demo instance is reset on regular basis, so feel free to play with it but don’t rely on it for persistent storage of your data.

Insert or update the document with _id docid
PUT /db/coll/docid

$ curl -i -H "key:demo,Content-Type:application/json" -X PUT https://beta.mrest.io/demo/messages/docid -d '{"from":"ujibang", "message":"RESTHeart rocks!!" }'

HTTP/1.1 201 Created
...

        

Get the created document

$ curl -H "key:demo" https://beta.mrest.io/demo/messages/docid

{
	"_id": "docid",
	"from": "ujibang",
	"message": "RESTHeart rocks"
}

        

Create a second document with POST /db/coll

If the _id is not specified in the request body, it will be autogenerated as a new ObjectId. The Location response header specifies the URL of the new document.

$ curl -i -H "key:demo,Content-Type: application/json" -X POST curl https://beta.mrest.io/demo/messages -d '{"from":"ujibang", "message": "MongoDB rocks as well!"}'

HTTP/1.1 201 Created
Location: https://beta.mrest.io/demo/messages/563a40d6e4b0ef984cae182b
...

        

Update the first document with PATCH /db/coll/docid

This request uses the dot notation and the $currentDate operator. These are available in all write requests!

$ curl -i -H "key:demo,Content-Type: application/json" -X PATCH https://beta.mrest.io/demo/messages/docid -d '{"$currentDate": { "header.timestamp": true}}'

HTTP/1.1 200 OK
...

        

Get the updated document again.

The returned representation contains all the document properties plus few more. The _etag is updated automatically by RESTHeart for Web caching and ghost writes management.

$ curl -H "key:demo" https://beta.mrest.io/demo/messages/docid

{
	"_id": "docid",
	"from": "ujibang",
	"message": "RESTHeart rocks!!",
	"header": {
		"timestamp": {
			"$date": 1475598488601
		}
	}
}

        

Find documents via query.

The filter query parameter allows to specify any MongoDB query.

This instance of RESTHeart is configured to always add the np query parameter to the request; it gets rid of the collection properties and returns just an array of documents.

$ curl -H "key:demo" -G --data-urlencode "filter={'from':'ujibang'}" https://beta.mrest.io/demo/messages

[   {
		"_id": "docid",
		"from": "ujibang",
		"message": "RESTHeart rocks!",
		"header": {
			"timestamp": {
				"$date": 1475598488601
			}
		}
	}, {
		"_id": {
			"$oid": "563a40d6e4b0ef984cae182b"
		},
		"from": "ujibang",
		"message": "MongoDB rocks as well!"
	}    
]