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-tapir

v0.15.5

Published

API routes wrapper

Downloads

7

Readme

Tapir API wrapper

Dear developer! Saddle one of our beautiful tapirs and have a good ride!

We made too much express routing and at one point we made a wrapper that handles:

  • routing
  • authorization
  • async methods
  • request options
  • errors
  • internal calls
  • API docs generation
  • API testing

Yes, our tapirs know that there is a swagger snorkelling out there. The Swagger is a great tool if you like to write (or generate) that enormous configuration files.

Tapir loves juicy requests with a body filled with JSON. We would change this behaviour in future releases.

How to install

Simple example

Concepts

Routing

Tapir likes to tie URI with the request method, but you can specify method as a route property if you wish.

Common CRUD for all standard tapir manipulations can look like this:

POST:/api/tapir
GET:/api/tapir
GET:/api/tapir/:id
PUT:/api/tapir/:id
REMOVE:/api/tapir/:id

Tapir options

const Tapir = require('api-tapir'),
      api = new Tapir({
        timeout: 66666,
        router: express.Router(),
        docs: 'GET:/myApi'
      });

router <express router>

Tapir would try to require express and create an instance of Router itself if this argument is not specified.

timeout <Number> = 30000

Default request timeout duration in milliseconds. You can overwrite it in the route options.

docs <String|falsy value> = GET:/api

API route options

Each of your API leaves can be configured

Keep in mind that all options are optional.

options <key-value> — query parameters

Specify all parameters that your api method needs. This specifications would be used for type checking, type casting, default values, documentation.

Tapir get parameters from request body < URI matched parts < URI query parameters

type — option type

Tapir knows basic types: Number, String, Boolean, Array, Date, "Any".

This would be extended in a future version. Tapir would be able to cast nested properties.

You can extend it in Tapir's module mappers. The extend method is a function that takes something as an argument and returns it in the proper data type. If input data is wrong — you MUST throw an Exception.

default — default property value
required <Boolean>

Tapir throws an Error if required property is not specified.

description <String> — describe the parameter

fn <Function> (args, request, response)

This is the function that is doing the real work. It can be async. If this function throws an Error — it would be sent in the response.

auth <Function> (args, request, response)

Authorization checking function that can be async. If specified — should return true if the user looks authorized enough.

Feel free to modify args object

description <String>

middleware <Function | [Function]>

Middleware pattern for queries processing. It is widely used in express.js, passport.js

middlewareAuth <Function | [Function]>

Just glued before anything in middleware

timeout <Number> = Tapir.config.timeout ≈ 30000

Request timeout duration in milliseconds.

maxBodyLength <Number> = 1e6

Specifies maximum request size