User Tools

Site Tools


wiki:oss_api

This is an old revision of the document!


Operational Support System

The OSS has several interfaces that can be accessed through APIs.

REST

A RESTful Web services architecture follows basic design principles:

  • It exposes a tree of resources via URI
  • It is stateless. Each request from any client contains all the information necessary to service the request, and session state is held in the client.
  • A resource is represented by an hypermedia type, for example JSON
  • It uses HTTP methods explicitly (GET, POST, PUT, DELETE, …) and other HTTP standards
  • hypertext links to reference state
  • hypertext links to reference-related resources

The API version level is requested by the client using the accept HTTP header, for example here with API v1:

Accept: application/vnd.kerlink.iot-v1+json

Example

GET http://kerlink.fr/oss/rest/application/customers/198/fleets?page=3&PageSize=40

This web service allows to get the page number 3 of the list of fleets of the customer 198.

The list of possible verbs is : GET, POST, PUT, DELETE, PATCH

  • POST: creates a new resource.
  • GET: gets a resource.
  • PUT: updates an existing resource.
  • DELETE: deletes a resource.
  • PATCH: updates a subset of fields of an existing resource.

Using the command-line

These examples use the command-line program curl to make HTTP requests.

If you want to test, you could also use mockable.io or any other tool of your choice.

Logging in

The use of the API is bound to a fresh token. Here is how you can request for a new token:

curl -s 'http://wanesyserver.tld/oss/application/login' \
  -H 'Accept: application/vnd.kerlink.iot-v1+json' \
  -X POST \
  -d '{"login":"jdoe","password":"P@ssW0rd5ecRe7"}' \
  -H 'Content-Type: application/vnd.kerlink.iot-v1+json' \
  | jq .

Here jq is used to prettify the JSON output so that it is readable and indented:

{
  "expiredDate": 1500537180050,
  "tokenType": "Bearer",
  "token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzdXBlcmFkbW ... n6i5WboHR-I"
}

Requesting the customers list

curl -s 'http://wanesyserver.tld/oss/application/customers' \
  -H 'Accept: application/vnd.kerlink.iot-v1+json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzdXBlcmFkbW ... n6i5WboHR-I' \
  | jq .

Result:

{
  "count": 2,
  "pageSize": 50,
  "page": 1,
  "totalCount": 2,
  "list": [
    {
      "id": 130,
      ...
    }
  ],
  "nbPages": 1
}

wiki/oss_api.1510070979.txt.gz · Last modified: 2017/11/07 17:09 by tda