Update rest.md

This commit is contained in:
Raymond Feng 2013-08-26 10:20:06 -07:00
parent 67596bd137
commit c604c708cf
1 changed files with 61 additions and 60 deletions

View File

@ -48,16 +48,15 @@ By default, the REST APIs are mounted to `/pluralFormOfTheModelName`, for exampl
### CRUD remote methods ### CRUD remote methods
- Model.create - Model.create: POST /locations
- Model.upsert - Model.upsert: PUT /locations
- Model.exists - Model.exists: GET /locations/:id/exists
- Model.findById - Model.findById: GET /locations/:id
- Model.find - Model.find: GET /locations
- Model.findOne - Model.findOne: GET /locations/findOne
- Model.deleteById - Model.deleteById: DELETE /locations/:id
- Model.count - Model.count: GET /locations/count
- Model.prototype.updateAttributes - Model.prototype.updateAttributes: PUT /locations/:id
- Model.prototype.reload
### Custom remote methods ### Custom remote methods
@ -78,6 +77,7 @@ To expose a JavaScript method as REST API, we can simply describe the method as
); );
The remoting is defined using the following properties: The remoting is defined using the following properties:
- description: Description of the REST API - description: Description of the REST API
- accepts: An array of parameter description - accepts: An array of parameter description
- returns: Description of the return value - returns: Description of the return value
@ -95,11 +95,11 @@ Create a new instance of the model and persist it into the data source
POST /locations POST /locations
####Arguments ####Arguments
* **data** * **data** The model instance data
####Example Request ####Example Request
curl -X POST -H "Content-Type:application/json" -d '' http://localhost:3000/locations curl -X POST -H "Content-Type:application/json" -d '{"name": "L1", "street": "107 S B St", "city": "San Mateo", "zipcode": "94401"}' http://localhost:3000/locations
####Example Response ####Example Response
@ -111,7 +111,7 @@ Create a new instance of the model and persist it into the data source
###upsert ###upsert
Update or create a model instance Update an existing model instance or insert a new one into the data source
####Definition ####Definition
@ -119,11 +119,11 @@ Update or create a model instance
PUT /locations PUT /locations
####Arguments ####Arguments
* **data** * **data** The model instance data
####Example Request ####Example Request
curl -X PUT -H "Content-Type:application/json" -d '' http://localhost:3000/locations curl -X PUT -H "Content-Type:application/json" -d '{"name": "L1", "street": "107 S B St", "city": "San Mateo", "zipcode": "94401"}' http://localhost:3000/locations
####Example Response ####Example Response
@ -135,7 +135,7 @@ Update or create a model instance
###exists ###exists
Check the existence of a model instance by id Check whether a model instance exists by id in the data source
####Definition ####Definition
@ -143,7 +143,7 @@ Check the existence of a model instance by id
GET /locations/exists GET /locations/exists
####Arguments ####Arguments
* **id** * **id** The model id
####Example Request ####Example Request
@ -162,7 +162,7 @@ Check the existence of a model instance by id
###findById ###findById
Retrieve a model instance by id Find a model instance by id from the data source
####Definition ####Definition
@ -170,7 +170,7 @@ Retrieve a model instance by id
GET /locations/{id} GET /locations/{id}
####Arguments ####Arguments
* **id** * **id** The model id
####Example Request ####Example Request
@ -197,7 +197,7 @@ Retrieve a model instance by id
###find ###find
Find all model instances matching the filter Find all instances of the model matched by filter from the data source
####Definition ####Definition
@ -205,8 +205,20 @@ Find all model instances matching the filter
GET /locations GET /locations
####Arguments ####Arguments
* **filter** * **filter** The filter that defines where, order, fields, skip, and limit
Properties for the filter object:
where - Object { key: val, key2: {gt: 'val2'}}
include - String, Object or Array.
order - String "key1 ASC, key2 DESC"
limit - Number The max number of items
skip - Number The number of items to be skipped
fields - Object|Array|String A list of properties to be included or excluded
['foo'] or 'foo' - include only the foo property
['foo', 'bar'] - include the foo and bar properties
{foo: true} - include only foo
{bat: false} - include all properties, exclude bat
####Example Request ####Example Request
curl http://localhost:3000/locations curl http://localhost:3000/locations
@ -245,7 +257,7 @@ Find all model instances matching the filter
###findOne ###findOne
Find one model instance matching the filter Find first instance of the model matched by filter from the data source
####Definition ####Definition
@ -254,7 +266,20 @@ Find one model instance matching the filter
GET /locations/findOne GET /locations/findOne
####Arguments ####Arguments
* **filter** * **filter** The filter that defines where, order, fields, skip, and limit
Properties for the filter object:
where - Object { key: val, key2: {gt: 'val2'}}
include - String, Object or Array.
order - String "key1 ASC, key2 DESC"
limit - Number The max number of items
skip - Number The number of items to be skipped
fields - Object|Array|String A list of properties to be included or excluded
['foo'] or 'foo' - include only the foo property
['foo', 'bar'] - include the foo and bar properties
{foo: true} - include only foo
{bat: false} - include all properties, exclude bat
####Example Request ####Example Request
@ -281,7 +306,7 @@ Find one model instance matching the filter
###deleteById ###deleteById
Delete a model instance by id Delete a model instance by id from the data source
####Definition ####Definition
@ -289,7 +314,7 @@ Delete a model instance by id
DELETE /locations/{id} DELETE /locations/{id}
####Arguments ####Arguments
* **id** * **id** The model id
####Example Request ####Example Request
@ -305,7 +330,7 @@ Delete a model instance by id
###count ###count
Count the number of model instances matching the where criteria Count instances of the model matched by where from the data source
####Definition ####Definition
@ -313,7 +338,7 @@ Count the number of model instances matching the where criteria
GET /locations/count GET /locations/count
####Arguments ####Arguments
* **where** * **where** The criteria to match model instances
####Example Request ####Example Request
@ -332,7 +357,7 @@ Count the number of model instances matching the where criteria
###nearby ###nearby
Find nearby locations around a given geolocation Find nearby locations around the geo point
####Definition ####Definition
@ -340,9 +365,9 @@ Find nearby locations around a given geolocation
GET /locations/nearby GET /locations/nearby
####Arguments ####Arguments
* **here** * **here** geo location object with `lat` and `lng` properties
* **page** * **page** number of pages (page size=10)
* **max** - max distance in miles * **max** max distance in miles
####Example Request ####Example Request
@ -379,10 +404,10 @@ Find nearby locations around a given geolocation
* None * None
###update ###updateAttributes
Update a model instance by id Update attributes for a model instance and persist it into the data source
####Definition ####Definition
@ -390,36 +415,12 @@ Update a model instance by id
PUT /locations/{id} PUT /locations/{id}
####Arguments ####Arguments
* **data** * **data** An object containing property name/value pairs
* **id** * **id** The model id
####Example Request ####Example Request
curl -X PUT -H "Content-Type:application/json" -d '' http://localhost:3000/locations/{id} curl -X PUT -H "Content-Type:application/json" -d '{"name': "L2"}' http://localhost:3000/locations/88
####Example Response
####Potential Errors
* None
###reload
Reload a model instance by id
####Definition
POST /locations/{id}/reload
####Arguments
* **id**
####Example Request
curl -X POST -H "Content-Type:application/json" -d '' http://localhost:3000/locations/{id}/reload
####Example Response ####Example Response