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

navitia

v1.0.0

Published

Navitia API wrapper

Downloads

6

Readme

navitia

library to query navitia API

Usage

An example is better than thousands words:

var navitia = require('navitia');
navitia
  .query(options) // call navitia API
  .regions() // ask for all regions
  .on('ready', function (res) {
    // result from API
  });

To call the API you must call the query method which will launch the HTTP call.

To listen to the result just add a listener callback on the ready event.

res is an object which have the following fields depending on the response returned by the API:

If the API return a valid response, it will have the following form:

  • statusCode: (int = 20x)
  • resource: (mixed) the resource asked for
  • pagination: (object) the pagination object if any returned or false
  • links: (array) a list of links from this resource

In case of error, the reponse will have the following form:

  • statusCode: (int >= 400)
  • error, (string) error message

Options passed to the query function is an object that can be helpful either to configure some queries or to control the behavior of the API querying, like asking for debugging, etc.

if you want to debug the call you should set debug key to true, and it will log the HTTP request, useful for debugging purpose.

Authentication

Since v1, all requests to Navitia API must be authenticated. Navitia supports both Basic HTTP authentication and HTTP Authorization header. This library only support the last option, which is HTTP Authorization header.

See navitia doc

The best way to provide the api key is to use a .env file using the format giben below. The example also set the debug flag to 0

apikey=abcdefgh-abcd-abcd-abcd-abcdefghijkl
debug=0

API

The examples below are not fully functional. You must call the query() for the HTTP call to be made and add a listener on ready event as explained in Usage section.

Regions: all the regions covered by navitia

navitia.query(/* options */).regions()

Region: show one region

navitia.query(/* options */).region('paris')

Lines: show lines in a given region

navitia.query(/* options */).region('paris').lines()

Lines: show a line in a given region

navitia.query(/* options */).region('paris').lines(/* line id */)