Nasal Piercings Manipulator
    Have ideas to improve npm?Join in the discussion! »

    native-api-service

    1.0.2 • Public • Published

    native-api-service

    A simple way to make API request from the client end

    Installation

    Use the package manager npm to install native-api-service.

    npm install native-api-service

    Explanation

    ApiService.request(method, path, callback, errorCallback, payload, exectuteWhileLoading);

    1. method: this is any of the HTTP request method - get, delete, head, options, posst, put, patch,
    2. path: this is the relative path to the needed resource - '/user'
    3. callback: this is a function that gets executed when the request is successful - (response) => console.log('response from API -> ', response)
    4. errorCallback: this is a error function that gets executed when the request fails - (error) => console.log('error from API -> ', error)
    5. payload (optional): this is an object that needs you to send data to the API - { key: value }
    6. exectuteWhileLoading (optional): this is a function that gets executed while the request is loading - NB: you can show a toast or upload progress

    Usage

    import { ApiService } from 'native-api-service';
     
    const userApiService = new ApiService('https://jsonplaceholder.typicode.com');
    // or
    // const userApiService = new ApiService('https://jsonplaceholder.typicode.com', 'Bearer **token**');
    // or
    // const userApiService = new ApiService('https://jsonplaceholder.typicode.com', 'Bearer **token**', 'application/json');
    userApiService.request(
        'get', 
        '/users',
        response => {
            console.log(response);
            return response;
        },
        error => {
            console.log(error);
            return error;
        },
        null,
        console.log('Loading all users...'),
    );
     

    Contributing

    Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

    License

    GNU

    Install

    npm i native-api-service

    DownloadsWeekly Downloads

    0

    Version

    1.0.2

    License

    GPL-3.0-or-later

    Unpacked Size

    39.9 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar