1.0.8 • Published 4 years ago

sdk-factory v1.0.8

Weekly downloads
66
License
MIT
Repository
gitlab
Last release
4 years ago

🏭 sdk-factory

Quickly build a JavaScript SDK to interface with any REST API.

Installation

yarn add sdk-factory

Usage

import { createSdk } from 'sdk-factory'

// Define the API schema
const schema = {
  name: 'Example API',
  endpoints: {
    user: {
      endpoints: {
        all: {
          method: 'GET',
          path: '/api/users',
        },
        get: {
          method: 'GET',
          path: '/api/users/:id',
        },
        update: {
          method: 'PUT',
          path: '/api/users/:id',
        },
        patch: {
          method: 'PATCH',
          path: '/api/users/:id',
        },
        delete: {
          method: 'DELETE',
          path: '/api/users/:id',
        },
        create: {
          method: 'POST',
          path: '/api/users',
        },
      },
    },
  },
}

// Create the SDK class.
const ExampleSdk = createSdk(exampleSchema)

// Create a new instance of the sdk to use it.
const instance = new ExampleSdk({ href: 'https://localhost:3000' })

instance.user().all()
  .then(users => console.log('Response from API: ', users))
1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago