overpass-ts
v4.3.8
Published
typescript overpass api
Downloads
1,187
Readme
overpass-ts
promise-based overpass api client in typescript
- works in browser & node
- support json & xml/text & stream response
- auto-retry if rate limit (409) or gateway timeout (504)
- helpful error messages
installation
npm install overpass-ts
api
overpass(query, opt = {})
query
: string Overpass API queryopt
: object Query optionsendpoint
string Overpass API endpoint URLrateLimitRetries
number Number of retries when rate limited/gateway timeout-ed before giving uprateLimitPause
number Pause in between receiving a rate limited response and initiating a retryverbose
boolean Output verbose query informationstream
boolean Return a stream.Readable (in Node) or ReadableStream (in browser)fetchOpts
object Options to be passed to fetch
Returns:
- If query is
[out:json]
, API response as JSON object - If query is
[out:xml]
or[out:csv]
, API response as string - If
opt.stream = true
, returnstream.Readable
(nodejs) /ReadableStream
(browser)
example
import type { OverpassJson } from "overpass-ts";
import { overpass } from "overpass-ts";
// json request
overpass(`[out:json]; node(626639517); out ids;`).then((json) => {
json = json as OverpassJson; // cast correct response type based on query
assert.deepStrictEqual(json.elements[0], {
type: "node",
id: 626639517,
});
});
license
MIT