to-api

    0.3.10 • Public • Published

    to-api

    Library to-api generates REST API client with fetch under the hood.

    Usage

    import create from 'to-api';
    
    const clientApi = create({ baseUrl: 'http://api/users' });
    
    clientApi
      .addHeader('Authorization', 'bearer ...')
      .processResponse(({ data }) => data);
    
    const usersClient = clientApi({
      create: 'POST /',
      updateById: 'PUT /:id',
      deleteById: 'DELETE /:id',
      find: '/',
      findById: 'GET /:id'
    });
    
    (async () => {
        const newUser = await usersClient.create({ email: 'user@example.com' });
        const user = await usersClient.findById({ id: 'user-id' });
    })();

    More examples you can find in tests.

    Install

    npm i to-api

    DownloadsWeekly Downloads

    5

    Version

    0.3.10

    License

    MIT

    Unpacked Size

    37.6 kB

    Total Files

    5

    Last publish

    Collaborators

    • vladimir.shushkov