1.0.0 • Published 3 months ago

@uniqoders/sdk v1.0.0

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
3 months ago

Uniqoders API SDK

The Uniqoders API SDK is a TypeScript-based library designed to enhance the interaction with your API. Offering structured, type-safe requests and responses, this SDK streamlines the process of communicating with the backend.

Features

  • Axios for HTTP Requests: Utilizes Axios for robust and efficient HTTP request management.
  • TypeScript Integration: Leverages TypeScript for type-safe interactions, reducing runtime errors.
  • JSON to TypeScript Object Mapping: Automatically maps JSON responses from the API to TypeScript objects.
  • Cancellable Requests: Supports cancelling of ongoing HTTP requests.
  • Customizable Configuration: Designed for easy and flexible configuration to fit various API interaction requirements.
  • Deserialization: Automatically maps JSON responses from JSON:API snake_case to camelCase without attributes, includes and relations

Installation

Install the SDK into your project using one of the following package managers:

Using Yarn

yarn add uniqoders-sdk

Using NPM or PNPM

npm install uniqoders-sdk

Usage

Initialization

Create an instance of ApiClient to start interacting with the API:

import ApiClient from '@uniqoders/sdk';

const API_URL = "https://api.example.com";
const HEADERS = {'Accept-Language': 'en'};

const apiClient = new ApiClient(API_URL, HEADERS);

Making API Requests

Use the ApiClient to perform API requests:

// Example of a GET request
apiClient.request({
    method: 'GET',
    url: '/users',
}).then(response => {
    console.log(response.data);
});

Response Handling

The responses are automatically parsed into the appropriate TypeScript objects:

apiClient.request({method: 'GET', url: '/user/1'})
    .then(response => {
        // Assuming response is a User object
        console.log(response.data.name);
    });

Advanced Features

Cancellable Requests

For scenarios such as rapid search where requests need to be cancelled:

apiClient.request({
    method: 'GET',
    url: '/search',
    params: {query: 'example'},
    options: {cancellable: true, cancelKey: 'searchRequest'}
});

Custom Object Mapping

You can define custom mappings for your TypeScript models:

class User extends BaseObject {
    // User model definition
}

// Set custom object mappings
apiClient.setObjects({
    user: attrs => new User(attrs)
});

How to Work

The library includes various npm scripts to facilitate development and build processes. These scripts can be executed using pnpm, npm, or yarn, based on your preference.

Available Scripts

  • "_clear": Cleans the build directories by removing all files in build/compiled and dist. Uses rimraf for safe and effective deletion across different platforms.

    pnpm run _clear
  • "_tsc": Compiles the TypeScript files of the project using the TypeScript compiler (tsc). This produces JavaScript files ready to be bundled and deployed.

    pnpm run _tsc
  • "_make-bundle": Bundles the project using rollup with the configuration defined in the Rollup config file.

    pnpm run _make-bundle
  • "build": Runs a series of scripts in sequence to clean, compile, and bundle the library. This script is a combination of the previous scripts, ideal for preparing the project for production.

    pnpm run build
  • "lint": Executes eslint to identify and report on patterns found in ECMAScript/JavaScript code, helping to maintain code quality and consistency.

    pnpm run lint
  • "lint:write": Similar to lint, but also attempts to fix automatically fixable issues in the code.

    pnpm run lint:write

These scripts enhance the development experience by streamlining tasks like cleaning build directories, compiling TypeScript files, bundling the final output, and maintaining code quality with linting.

1.0.0

3 months ago

1.0.0-beta.11

3 months ago

1.0.0-beta.10

4 months ago

1.0.0-beta.9

4 months ago

1.0.0-beta.6

4 months ago

1.0.0-beta.7

4 months ago

1.0.0-beta.8

4 months ago

1.0.0-beta.4

4 months ago

1.0.0-beta.5

4 months ago

1.0.0-beta.2

4 months ago

1.0.0-beta.3

4 months ago

1.0.0-beta.1

4 months ago

0.2.10

5 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.2.7

8 months ago

0.2.6

8 months ago

0.2.9

6 months ago

0.2.8

7 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.1.5

10 months ago

0.1.4

11 months ago

0.1.0

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.1.3

11 months ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.26

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago