2.2.0-alpha • Published 6 years ago

@misakey/api v2.2.0-alpha

Weekly downloads
17
License
SEE LICENSE IN /L...
Repository
gitlab
Last release
6 years ago

@misakey/api

yarn add @misakey/api

An instance of Class API implements one method: API.use().

use accepts as parameter an endpoint Types Definition defined like this:

export default {
  read: {
    method: 'GET',
    path: '/applications/:mainDomain',
    auth: true,
  },
};

It's possible to nest Types Defs

API instance is constructed with these Types Definition that are given as parameters to the use method:

// src/screens/MyScreen
import API from '@misakey/api';
import Endpoint from '@misakey/api/endpoints/Endpoint';

const myEndpoint = API.use(API.endpoints.application.read);
console.log(myEndpoint instanceof Endpoint); // true

As you can see use returns a Class Endpoint instance which implements the following methods (build and send):

// src/screens/MyScreen
import API from '@misakey/api';

console.log(locationParams); // { mainDomain: 'misakey.com', otherLocationParam: true }

const params = locationParams;
const payload = undefined;
const queryParams = undefined;

const myRequestPromise = API.use(API.endpoints.application.read)
  .build(params, payload, queryParams)
  .send();

console.log(myRequestPromise instanceof Promise); // true

myRequestPromise.then(response => console.log(response)); // { httpStatus: 200, body: {} }

If a mock is implemented you can call fakeReponse method with an httpStatus code: API.use(API.endpoints.application.read).fakeResponse(200).then(handleResponse);

New endpoints need to compel with rules defined in @src/api/API.test.js

2.2.0-alpha

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago