1.1.13 • Published 28 days ago

abra.js v1.1.13

Weekly downloads
-
License
MIT
Repository
github
Last release
28 days ago

Abra.JS

This library is still in development, and should not be used in production.

Abra.JS is a simple, lightweight, and easy to use Javascript library for HttP requests.

It is a wrapper around the native fetch API, and is designed to be as simple as possible.

Installation

Abra.JS is available on NPM, and can be installed with the following command:

npm install abra.js

Import the library in your project:

import Abra from "abra.js";
// Get an instance of Abra
const abra = Abra();

Or, alternatively :

const Abra = require("abra.js").default();

You can also use the CDN version of the library, by adding the following script tag to your HTML file:

<script src="https://cdn.jsdelivr.net/npm/abra.js/dist/index.min.js"></script>

Usage

Abra.JS is designed to be as simple as possible, and is designed to be used in a similar way to the native fetch API. No more .json() method, you can use your datas in the .data property of the response.

import Abra from 'abra.js';
const abra = Abra();

abra.get('https://example.com')
    .then(res => console.log(res.data));

Abra.JS also supports the use of async/await, which is recommended for use in production.

import abra from 'abra.js';

async function getData() {
    const {data} = await abra.get('https://example.com');
    console.log(data);
}

Documentation

Abra.JS is designed to be as simple as possible.

Get

Simple get request :

    abra.get(url, options);
  • url : (string) url to fetch
  • options : (object) the options for the request ( params, headers, and any fetch options available);

Post, Put, Patch

Simple post request :

    abra.post(url, body, options);
  • url : (string) url to fetch
  • body : (object) the data to send ( any type accepted by fetch )
  • options : (object) the options for the request ( params, headers, and any fetch options available)

Exemple :

    abra.post('https://example.com', 
        { name: 'Jean Micheline' }, 
        { headers: 
                { 'Content-Type': 'application/json' } 
        });

There is no need to specify the content-type for JSON data. You don't need to transform your data to JSON, Abra.JS will do it for you.

For every other type of data, you need to specify the content-type, and perform the transformation yourself.

Delete

Simple delete request :

    abra.delete(url, options);

Options

Basically any fetch options available ( see MDN ) can be used.

Abra.JS also adds params options, which is an object containing the query parameters to add to the url.

    abra.get('https://example.com', { params: { name: 'Jean Micheline' } });

Caution : the method option, available in fetch, is not supported by Abra.JS, as it is automatically set by the method used.

Interceptors

Abra.JS provides interceptors, which are functions that are called before the request is sent, and before the response is returned.

Interceptors are useful to add headers, or to modify the request before it is sent.

You can add 'in' interceptors, which are called before the request is sent, and 'out' interceptors, which are called before the response is returned.

You can add interceptors with the following methods :

    // Add an interceptor for requests
    abra.addInInterceptor((request) => {
        // do something with the request
        return request;
    });


    // Add an interceptor for responses
    abra.addOutInterceptor((response) => {
        // do something with the response
        return response;
    });

License

I have no idea what license to use, but feel free to use this however you want.

Author

Abra.JS was created by Thaïs Révillon. You can find me on LinkedIn at @ThaisRevillon.

Contributing

Feel free to contribute to this project, I will be happy to review your pull requests ! Just make sure to follow the code style of the project, and the main goals of the project : simplicity and lightweight.

Versioning

This project is still in development, and is not yet ready for production. This is a personal project, and I will try to update it as much as possible, add tests and new features.

1.1.13

28 days ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.0-beta.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

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