RESTHeart Angular demo

A Simple Web Application

This is a very simple Angular Web Application hosted at ng-demo.restheart.org. It shows a table of message documents stored in a MongoDB collection and provides a simple form to create a new message document.

Click on Editor button below and open the code of service.ts. You’ll see how is easy interacting with the RESTHeart API!

Source code is available at restheart-ng-demo official Github repository!

For a more complete Angular application that uses exactly the same REST API, please have a look at our Webchat example.

Try the API online

You can use the online demo service so you can play with API without the need to install MongoDB and RESTHeart.

The online demo API exposes one single collection at https://demo.restheart.org/messages without requiring authentication.

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

$ curl -i -H "Content-Type:application/json" -X PUT https://demo.restheart.org/messages/docid?wm=upsert -d '{"from":"you", "message":"RESTHeart rocks!!" }'

HTTP/1.1 201 Created
Open on rest ninja

This request uses write mode set to upsert. Since RESTHeart v5.3.0, write mode for PUT/PATCH requests is set by default to update. Check out here for more informations.

Get the created document

$ curl -i https://demo.restheart.org/messages/docid

{
	"_id": "docid",
	"from": "you",
	"message": "RESTHeart rocks"
}
Open on rest ninja

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 "Content-Type:application/json" -X POST https://demo.restheart.org/messages -d '{"from":"you", "message": "MongoDB rocks as well!"}'

HTTP/1.1 201 Created
Location: https://demo.restheart.org/messages/563a40d6e4b0ef984cae182b
...
Open on rest ninja

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 "Content-Type:application/json" -X PATCH https://demo.restheart.org/messages/docid -d '{"$currentDate": { "header.timestamp": true}}'

HTTP/1.1 200 OK
...
Open on rest ninja

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 -i https://demo.restheart.org/messages/docid

{
	"_id": "docid",
	"from": "you",
	"message": "RESTHeart rocks!!",
	"header": {
		"timestamp": {
			"$date": 1475598488601
		}
	}
}
Open on rest ninja

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 -G --data-urlencode "filter={'from':'you'}" https://demo.restheart.org/messages?pagesize=2

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