npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

native-service

v1.0.1

Published

[React-native] Now, you can make an api request easiest. Cache, Paginate, Checking error, Transformation, Urlencoded It use apisauce for requesting Next: upload, download (Comming soon)

Downloads

4

Readme

native-service

[React-native] Now, you can make an api request easiest. Cache, Paginate, Checking error, Transformation, Urlencoded It use apisauce for requesting Next: upload, download (Comming soon)

Build Status

Getting started

$ npm install native-service --save

ServiceManager.js:

import Service from 'native-service';
import UserService from "./UserService";
import SampleService from './SampleService'

export class ServiceManager {
    constructor() {
        Service.config({
            baseURL: 'https://api.something.com',
            timeout: 5000
        });
        this.sampleService = new SampleService();
    }
    
    getSampleService = () => {
        return this.sampleService;
    }
}
export const serviceManager = new ServiceManager();

SampleService.js

import { GET, POST } from "native-service";

export default class SampleService {

    login = POST('/auth/login').cache("login");
    
    getInfo = POST('/info/{userId}');
    
    //Paginated API
    getPaginatedList = GET('/list').paginate((currentPage) => {
        return {
            orderType: 'asc',
            size: 20,
            page: currentPage
        };
    });
    
    //Override url only for this api
    apiToOtherServer = GET('another/server').overrideConfig({
        baseURL: 'https://api.anotherserver.com',
        timeout: 10000
    });

}

FUNCTIONS | Functions | What for | Both ios/android | | ------------- |:-------------:| -----:| | cache("key") | After requesting, save the result to Cache, with name "key" | ✓ | | header({}) | Header | ✓ | |transform((response) => { return response; })| Transform response data| ✓ | |paginate((currentPage) => {return {orderType: 'asc',size: 20,page: currentPage};});| This api is paginated| ✓ | |overrideConfig({ baseURL: '', timeout: 1000 }) | Override config only for current api | ✓ | |raw,urlencoded| default is raw |✓ |

Call Request

//Login API
var api = serviceManager.getSampleService().login;
var connect = await api.data({ username: "abc", password: "123"}).connect(); //Connect is your result
if(api.isError() || api.isClientError() || api.isServerError() || api.isTimeoutError() || api.isConnectionError() || api.isNetworkError() || api.isCancelError()) {
    //There is error in connection
}
//
var api2 = serviceManager.getSampleService().getPaginatedList;
var connect = await api2.data({ }).connect();//Connect is your result
var nextPage = await api2.data({ }).nextPage();//nextPage is your result
var pageAtPosition3 = await api2.data({ }).page(3);//pageAtPosition3 is your result

FUNCTIONS | Functions | What for | Both ios/android | | ------------- |:-------------:| -----:| | data({}) | Data to request | ✓ | | connect() | Send request now | ✓ | | nextPage() | Request next page | ✓ | | page(3) | Request the page at position 3 | ✓ |

#ERROR | ERROR | Check if | Both ios/android | | ------------- |:-------------:| -----:| | isError() | There is any error | ✓ | | isClientError() | Any non-specific 400 series error. | ✓ | | isServerError() | Any 500 series error. | ✓ | | isTimeoutError() | Server didn't respond in time. | ✓ | | isConnectionError() | Server not available, bad dns. | ✓ | | isNetworkError() | Network not available. | ✓ | | isCancelError() | Request has been cancelled. | ✓ |