restapibundle-sdk

1.0.9 • Public • Published

restapibundle-sdk

Symfony nbo/rest-api-bundle official client SDK

  • Consume REST API resources and sub resources
  • Sort and filter resources
  • Pagination
  • i18n support
  • Promise instead of API response for more flexibility
  • Out of the box JWT Authentication
  • Fully customizable

See this composer package and the corresponding repository for more informations.

https://packagist.org/packages/nbo/rest-api-bundle

https://gitlab.com/nicolasbonnici/restapibundle-sdk#readme

Setup

npm i --save restapibundle-sdk

Usage

Authentication

Get an API resource

Let's say you wanna query the "foo" resource corresponding to your Foo Doctrine backend entity.

// Load SDK
let oApi = oSdk({ api_scheme: 'http', api_host: 'localhost:8000' })

// Get resource with "key" field equal to "value"
oApi.get('foo', {q: { "key": "value" } })
    .then((oResponse) => { 
        console.log(oResponse) 
    }).catch(e => {
        console.log(e)
    })

Query API

Operators

You can also use SQL like operators to perform more complex queries.

// Get resources with "key" field equal to "value"
oApi.get('foo', {q: { "key": { '=' : "value" } } })...

// Get resources with "key" field different than "value"
oApi.get('foo', {q: { "key": { '!=' : "value" } } })...

// Get resources with "key" field greater than 10 value
oApi.get('foo', {q: { "key": { '>' : 10 } } })...

// Get resources with "key" field lesser than 10 value
oApi.get('foo', {q: { "key": { '<' : 10 } } })...

// Perform search on ressources with "key" field containing the term "search"
oApi.get('foo', {q: { "key": { 'LIKE' : '%search%' } } })...

Sort

You can sort results with the "sort" parameter.

// Sort parameter syntax
sort[key]: desc // desc

I18N

When resource are translatable, you can add a "locale" parameter corresponding to the current request locale.

Pagination

Api results are automatically paginated, you can customize the current page with the page parameter and also the results per page number with the limit parameter.

If you need to count total API resources without pagination, you can pass a count parameter, the response will contain a count header with the total resources count.

Readme

Keywords

Package Sidebar

Install

npm i restapibundle-sdk

Weekly Downloads

0

Version

1.0.9

License

GPL-3.0

Unpacked Size

169 kB

Total Files

12

Last publish

Collaborators

  • nicolasbonnici