UNPKG

3 kBMarkdownView Raw
1# An OpenAPI Directory for JS [![Travis Build Status](https://img.shields.io/travis/httptoolkit/openapi-directory-js.svg)](https://travis-ci.org/httptoolkit/openapi-directory-js) [![npm version](https://badge.fury.io/js/openapi-directory.svg)](https://badge.fury.io/js/openapi-directory)
2
3> _Part of [HTTP Toolkit](https://httptoolkit.tech): powerful tools for building, testing & debugging HTTP(S)_
4
5This repo builds & bundles the [OpenAPI Directory](https://github.com/APIs-guru/openapi-directory), so you can easily find, require and use any OpenAPI spec from the directory in your JS projects.
6
7It provides files that can be individually required or remotely downloaded (via https://unpkg.com/openapi-directory/) for every API in the collection, and an index to quickly find the relevant OpenAPI spec for a given URL.
8
9All specs are:
10
11* Pre-parsed and exposed as JavaScript objects (not YAML strings).
12* Converted to OpenAPI v3.
13* Pre-bundled with all external $refs.
14
15That means you can import them, and immediately & consistently start using them.
16
17## How to use it
18
19First up, install it with:
20
21```bash
22npm install openapi-directory
23```
24
25All OpenAPI specs can be now required with:
26
27```js
28const spec = require('openapi-directory/api/<spec-id>.json');
29```
30
31(or read from `https://unpkg.com/openapi-directory/api/<spec-id>.json`)
32
33The easiest way to obtain a spec id is to use the index. You can look up a URL in the index with:
34
35```js
36const { findApi } = require('openapi-directory');
37
38findApi('wikimedia.org/api/rest_v1/feed/availability');
39```
40
41`findApi` takes a URL (host and path, _without_ the protocol) within any API, and will return either:
42
43* Undefined, if there is no matching APIs.
44* A string spec id, if there is exactly one API that's relevant to that URL.
45* A list of spec ids, in rare cases where multiple specs may cover the same URL.
46
47Alternatively if you know in advance which spec you want you can require it directly. The id for every spec in the directory is made up of the provider name, followed by a slash and the service name if a service name exists. Some example ids:
48
49* `xkcd.com` (provider is xkcd.com, no service name)
50* `amazonaws.com/acm` (provider is amazonaws.com, service name is acm).
51
52You can find the provider and service name in the spec itself (under `info`, `x-providerName` and `x-serviceName`), and you can browse the raw specs directly at https://github.com/APIs-guru/openapi-directory.
53
54## License
55
56This repo/npm module is licensed as MIT.
57
58The license for API definitions varies by spec, see https://github.com/APIs-guru/openapi-directory#licenses for more information.
59
60In general it's very likely that your use of any API definition is covered either by CC0 (for specs submitted directly to the directory), the spec's own license (check `info.license`) or by Fair Use provisions when communicating with the corresponding service. This is not formal legal advice though, its your responsibility to confirm this for yourself for the specs you're using.
\No newline at end of file