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

rapid.js

v1.2.3

Published

<p align="center"> <img src="https://rapidjs.io/images/rapid-logo-gh-readme.png" /> </p>

Downloads

77

Readme

npm npm npm

An ORM-like Interface and a Router For Your API Requests
Create simple, reusable, and cleaner wrappers, define custom routes, and more for your API requests.

Read the official docs at https://rapidjs.io.

Installation

Pick your poison:

yarn add rapid.js
npm i -S rapid.js
npm install --save rapid.js

Overview

Define Simple Models

const post = new Rapid({ modelName: 'Post' });

post.find(1).then((response) => {
    // GET => /api/post/1
});

post.collection.findBy('category', 'featured').then((response) => {
    // GET => /api/posts/category/featured
});

post.withParams({ limit: 20, order: 'desc' }).all().then((response) => {
    // GET => /api/posts?limit=20&order=desc
});

post.update(25, { title: 'Rapid JS Is Awesome!' })
    // POST => /api/posts/25/update

post.destroy(9)
    // POST => /api/posts/9/destroy

post.restore(9)
    // POST => /api/posts/9/restore    

Read more about Rapid Basics.

Easily Customize Your API Requests

const post = new Rapid({
    modelName: 'Post',
    suffixes: {
        destroy: '',
        update: 'save'
    },
    methods: {
        destroy: 'delete'
    },
    trailingSlash: true
 });

post.update(25, { title: 'Rapid JS Is Awesome!' })
    // POST => /api/posts/25/save/

post.destroy(9)
    // DELETE => /api/posts/9/

Read more about Customizing Your Requests.

Create Reusable Base Models

class Base extends Rapid {
    boot () {
        this.baseURL = 'https://myapp.com/api';
        this.config.globalParameters = { key: 'MY_API_KEY' }
    }
}

const photo = new Base({ modelName: 'Photo' });
const gallery = new Base({ modelName: 'Gallery' });
const tag = new Base({ modelName: 'Tag' });

photo.find(1)
    // GET => https://myapp.com/api/photo/1?key=MY_API_KEY

tag.collection.findBy('color', 'red')
    // GET => https://myapp.com/api/tags/color/red?key=MY_API_KEY

gallery.id(23).get('tags', 'nature')
    // GET => https://myapp.com/api/gallery/23/tag/nature?key=MY_API_KEY

Read more about Base Models.

Write API Wrappers For Your Endpoints

class GalleryWrapper extends Rapid {
    boot () {
        this.baseURL = 'https://myapp.com/gallery/api';
        this.modelName = 'Gallery';
    }

    tagSearch (query) {
        return this.url('tagsearch').withParam('query', query);
    }

    json () {
        return this.url('json');
    }
}

const gallery = new GalleryWrapper({
    globalParameters: { key: 'MY_API_KEY' }
});

gallery.tagSearch('nature').json().get().then(...);
    // GET https://myapp.com/gallery/api/tagsearch/json?query=nature&key=MY_API_KEY
    // GET https://myapp.com/gallery/api/tagsearch/json?query=nature&key=MY_API_KEY

Read more about Making a Wrapper.

Define Custom Routes

const customRoutes = [
    {
        name: 'web_get_user_preferences',
        type: 'get',
        url: '/user/preferences',
    },

    {
        name: 'web_save_user_preferences',
        type: 'post',
        url: '/user/{id}/save/preferences'
    }
];

const router = new Rapid({ customRoutes, baseURL: '/api' });

router.route('web_get_user_preferences').then((response) => {}); 
// GET => /api/user/preferences

router.route('web_save_user_preferences', { id: 12 }, /* { request data } */).then((response) => {}); 
// POST => /api/user/12/save/preferences

Using Your Own HTTP Service

import http from 'some-http-service';

const customRoutes = [
    {
        name: 'web_login',
        url: '/login'
    },

    {
        name: 'api_save_user_preferences',,
        url: '/user/{id}/save/preferences'
    }
];

const rapid = new Rapid({ customRoutes, baseURL: '' });

rapid.generate('web_login')
// returns '/login'

// use your own service
http.post(rapid.generate('api_save_user_preferences', { id: 1 }), { data }).then()...

Read more about Custom Routes.

Read the official docs at https://rapidjs.io.