REST API Library

Allows other sites to read and write data on your site, using HTTP requests. Output is in JSON.

Using with AppJet

To use this library in your AppJet app, put import('lib-rest-api') at the top of your code. Now other sites and apps will be able to read and write data to your app. The functions rest.read() and rest.write() allow you to read and write to other apps using this library in an easier way.

Examples

Replace "example" with the name of your app in URIs.

Read an object

Suppose you have an object with an ID of obj-i.
http://example.appjet.net/api?id=obj-i

rest.read(objectId, appName)

rest.read('obj-i', 'lib-rest-api')

Read a set of objects

Suppose you have a collection, col-c, and you want to find all the objects where property p0 is equal to the value v. You may do any of the following: sort the objects by some property p1, skip the first s objects, and limit it to l objects. To reverse the sorting, add a - to the beginning of p1.


http://example.appjet.net/api/filter?_collection=col-c&p0=v&sortBy=p1&skip=s&limit=l
rest.read(filter, collection, appName)

rest.read({p0: v, sortBy: p1, skip: s, limit: l}, c, *)

The response is an object with one property, view. Its value is an array of the matching objectsobjects.

Write a new object

POST data to http://example.appjet.net/api/write, specifying the _collection , by its id or its name if it is a property of the storage object).

rest.write(data, collection, appName)

rest.write({p: v}, c, *)

If the write is successful, the response will be the id of the new object. {"id":"obj-LJZbtopnJ"}

Powered by AppJet
source
rendered in 0.019s