Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derhuerst/hafas-rest-api-client
An API client for hafas-rest-api endpoints.
https://github.com/derhuerst/hafas-rest-api-client
hafas-client public-transport transit
Last synced: 5 days ago
JSON representation
An API client for hafas-rest-api endpoints.
- Host: GitHub
- URL: https://github.com/derhuerst/hafas-rest-api-client
- Owner: derhuerst
- License: isc
- Created: 2016-06-05T01:00:40.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-02T11:11:27.000Z (about 1 year ago)
- Last Synced: 2024-10-03T23:56:01.312Z (about 1 month ago)
- Topics: hafas-client, public-transport, transit
- Language: JavaScript
- Homepage: https://github.com/derhuerst/hafas-rest-api-client
- Size: 93.8 KB
- Stars: 6
- Watchers: 5
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# hafas-rest-api-client
**A client for [`hafas-rest-api`](https://github.com/public-transport/hafas-rest-api) endpoints**, e.g. for [the `*.transport.rest` APIs](https://transport.rest/).
[![npm version](https://img.shields.io/npm/v/hafas-rest-api-client.svg)](https://www.npmjs.com/package/hafas-rest-api-client)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/hafas-rest-api-client.svg)
![minimum Node.js version](https://img.shields.io/node/v/hafas-rest-api-client.svg)
[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)
[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)## Installing
```shell
npm install hafas-rest-api-client
```## Usage
```js
import createClient from 'hafas-rest-api-client'const vbbClient = createClient('https://v5.vbb.transport.rest', {
// Please pass in a User-Agent header to let the providers of the API endpoint understand how you're using their API.
userAgent: 'my awesome project',
})const res = await vbbClient.journeys('900000003201', '900000024101', {results: 1})
````hafas-rest-api-client` is a client for [`hafas-rest-api@3`](https://www.npmjs.com/package/hafas-rest-api/v/3.8.0) APIs. Check their individual API docs for all supported parameters.
The response objects have special [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) fields for meta information:
```js
const {
RESPONSE, HEADERS,
SERVER_TIMING, CACHE,
} = require('hafas-rest-api-client')console.log('response', res[RESPONSE]) // Fetch API Response object
console.log('response headers', res[HEADERS]) // Fetch API Headers object
console.log('server timing', res[SERVER_TIMING]) // value of the Server-Timing response header
console.log('server cache', res[CACHE]) // value of the X-Cache response header
```## Contributing
If you have a question or have difficulties using `hafas-rest-api-client`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to [the issues page](https://github.com/derhuerst/hafas-rest-api-client/issues).