Skip to content

REST API

Henrik Östman edited this page Dec 3, 2013 · 9 revisions

https://apigee.com/trycoon/embed/console/jel

Basics

How a REST-call is constructed

/[domain]/[resource]/[param1-value]?[parameter=parameterValue]&[parameter=parameterValue]

Simple call upon a resource returns a collection of this resource, in this case a array of users.

/user/users

To be more specific a query could be provided as a parameter to specify we are only interested in user with id equals to 10.

/user/users?id=10

More parameters could be provided to some resources to narrow down what we are interested in.

/user/users?firstName=donald&lastName=duck&species=duck

A parameter could also be part of the path, but only one could be used in the path. Normally it refers to the Id of the resource. In this case we are requesting information about user with id=10.

/user/users/10

If we have more parameters they have to be part of a query, like this. We are requesting the full information about user with id=10.

/user/users/10?info=full

Range-queries, Paging, and Sort-order on collections

When working with collections that should be returned, range-queries, paging, and sort-order is supported.

The reserved words "skip" and "take" are used to support paging within the resource. Skip tells the API how many entities ignore, starting from the beginning, and "take" tells the API how many entities we are interested in there after. In this example we get back user 31 to 40.

/user/users?skip=30&take=10

Paging using Javascript code could look like this. var pageNumber = 3; var numberOfObjectsPerPage = 10; var restUri='/user/users?skip=' + (numberOfObjectsPerPage * pageNumber) + '&take=' + numberOfObjectsPerPage

A shorthand version of paging exists that is very powerful, but can only be used on the "id"-field of the entity. Example, this gives us user with id=1 and user with id=2 and users with id 4 through 8 and user with id=10.

/user/users/1,2,4-8,10

Multifetching

The API supports fetching multiple non-related resources at once, with the help of a semicolon. The API will treat this as multiple calls to the API, but return the responses in one batch just as the requests came in. In this example we are requesting an user with id=10 and a site with id=2.

/user/users/10;/site/sites/2

Projection

Projection is supported through the reserved word "select", using this we can specify which parts of the entity we are interested in. This is important for low bandwidth devices were we want to be sure we are just sending the information that the client-application needs. If a user-entity consists of 100 KB information, why send all this when we for the moment only are interested in presenting the username?

In this example we are only returning the id and first name of user with id=10.

/user/users/10?select=id,firstName

Complex cases

/domain/resource1/param1?param2=value&select=~id,firstname;/domain/resource1/~id

Kaltura API multifetch: http://www.kaltura.com/api_v3/testmeDoc/?page=multirequest

http://stackoverflow.com/questions/389169/best-practices-for-api-versioning

http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http

http://jsonapi.org/format/

Clone this wiki locally