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

api-book

v0.2.4

Published

For Front-End Development, this library is easy to generate API fetch automatically by json ONLY!

Downloads

9

Readme

API-Book

npm Build Status npm Coverage Status dependencies Status

For Front-End Development, this library is easy to generate API fetch automatically by json ONLY!

api-book flow chart

This library provide the useful featues to generate API fetch objects automatically by json files(book), which back-end developer updated and maintained. Not only reduce communication costs of front-end and back-end, that need to synchronize information of RESTful API frequently, but increase program accuracy.

// Easy to sync the APIs document from back-end using book!

const book = {
    getUserPicture: {
        url: '/api/user/{{userId}}/profile',
        method: 'GET',
        request: {
            header: {
                clientId: 'tsfhlkjswifqWERWERGvdsfaf'
            },
            path: {
                userId: 536251
            },
            query: {
                picId: 12345
            },
            body: {}
        },
        response: {
            type: 'json'
        }
    }
};

Installation

npm install api-book

Features

  • Support all method to fetch API (GET, POST, OPTION etc)

Quick Start

The quickest way to get started with Api-book as shown below:

Install the executable:

npm install --save-dev api-book

Create the desired API document(book):

// book.js

const book = {
    getUserPicture: {
        url: '/api/user/{{userId}}/profile',
        method: 'GET',
        request: {
            path: {
                userId: 536251
            },
            query: {
            	picId: 12345
            },
            body: {}
        },
        response: {
            type: 'json'
        }
    }
};

Provide the appropriate host address:

const host = "http://localhost:9000";

Provide optional API parameters:

const init = {
    "headers": {
        "Accept": "application/json",
        "Content-type": "application/json;charset=UTF-8",
    },
    "credentials": "include"
};

Generate Api-book fetch and give appropriate parameters:

import api from 'api-book';
export default api({ host, book, init });

In order to send the API, import the above output modules and call each other the desired API in the module:

import api from './book.js';

const request = {
    path: {
        userId: 536251
    },
    query: {
        picId: 12345
    }
};
	
api.getUserPicture(request)
    .then(response => {
        /*
            We build Reactions for calling APIs that works successfully
        */
    })
    .catch(error => {
        /*
            We build Reactions for calling APIs that works fails
        */
    })
	

Finally, that will generate the fetch object automatically to call API which link likes:

http://localhost:9000/api/user/536251/profile?picId=12345 (method: GET)

Testing

If you want to test the api that is working with server-side providing request data, change the option param while you generate Api-book fetch:

export default api({ host, book, init, option: { testing: true } });

Example

If you want to try this library easily, please follow the instructions below:

Install the executable:

git clone https://github.com/yingray/api-book.git
cd api-book

Start the server:

npm start

Enter to http://localhost:9000, click the click button to inspect whether web page works successfully to request and catches the response. You can also refer to the files in the example folder of the package.

-- example              
	- index.html         (web page)
	- index.js           (main script to call API)
	- book.js            (access the api document)
	- bundle.js          (webpack bundle all scripts)

License

MIT License

Copyright (c) 2017 Ying-Ray Lu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.