RhapsodyJS creates automatically a RESTful API for each one of your models (that can be disabled setting the allowREST option of the model as false).

Terminology: documents are each of the data stored in a model collection

The RESTful API of each model can be accessed by the path: /data/ModelName, so you can:

  • POST /data/<ModelName> Insert a new document to the ModelName collection with the data sent via POST and returns it.
  • POST /data/<ModelName>/<id>/<RelationshipName> Insert a new document to the RelationshipName of the model ModelName with the given id.
  • GET /data/<ModelName> Return all documents of the model ModelName.
  • GET /data/<ModelName>/<id> Return the document of the model ModelName with the given id.
  • GET /data/<ModelName>/<id>/<RelationshipName> Return all documents of the RelationshipName of the model ModelName with the given id.
  • PUT /data/<ModelName>/<id> Update the document of the model ModelName with the data sent via PUT.
  • PATCH /data/<ModelName>/<id> Update partially the document of the model ModelName with the data sent via PATCH.
  • DELETE /data/<ModelName>/<id> Delete the document with the given id from the ModelName collection.

All theses request will first pass by the model middlewares (if any).

Query options

Attributes

If you want just some attributes, you can pass it with the option attrs separating them with commas, for example:

/data/ModelName/?attrs=name,registry

or

/data/ModelName/someID/?attrs=name,registry

Limit

You can limit the number of results you want to get in the responde using the option limit, for example:

/data/ModelName/?limit=10

It will return you the first 10 results.

Offset

If you want to skip some results, you can use the option offset, for example:

/data/ModelName/?offset=10

It will skip the first 10 results and return the rest.

Order by some attribute

You can order the results by some attribute using the option orderby, for example:

/data/ModelName/?orderby=age

If will return all the results, ordering them by the attribute "age".

Order

You can choose if the results will be in ascending or descending order using the option order with the value asc or desc (they are case insensitive), for example:

/data/ModelName/?order=asc

or

/data/ModelName/?order=desc