@lonelyplanet/open-planet-node
v2.46.1
Published
Node.js client for the Open Planet API.
Downloads
1,117
Readme
Open Planet Node
Node.js client for the Open Planet API.
Create a client
Define a few ENV variables...
AUTH_CLIENT_ID=your-client-id
AUTH_HOST=http://connect.qa.lonelyplanet.com
OPENID_HOST=http://connect.qa.lonelyplanet.com
OPEN_PLANET_HOST=http://stable.web.op-api-gateway.qa.lonelyplanet.com
Create a client with...
import createClient from "@lonelyplanet/open-planet-node"
const client = createClient();
Docs
Generate docs with...
npm run docs
Endpoint Examples
User
client.user.find({
username: "foo.user",
});
client.user.findById("1234");
Bookmark List
client.bookmarkList.findById(":listId");
client.bookmarkList.createList(":userId", { /** list attributes */ });
Filtering
Most endpoints support the following types of filtering...
client.user.find({
key: "some value",
});
// ?filter[user][key][equals]=some%20value
client.poi.find({
place_id: {
has_ancestor: "362228",
},
});
// ?filter[poi][place_id][has_ancestor]=362228
client.place.find({
name: {
like: "nashv",
},
});
// ?filter[place][name][like]=nashv
Pagination
You can paginate by passing in the following...
client.user.find({
limit: 10,
offset: 2
});
// ?page[limit]=10&page[offset]=2
Disable include service caching
If you find yourself getting back cached things via ?include
...
client.user.find({
nocache: true,
});
// ?nocache=true
Pass extra query string arguments
To pass additional non-filter query string arguments, use extras
...
client.user.find({
name: "someusername",
extras: {
foo: "bar"
}
});
// ?filter[user][name][equals]=someusername&foo=bar
Building
npm run build
npm run build -- --watch
Testing
npm run test
Dependency Injection with Inversify and Reflect-Metadata
Make sure to have the following code in the main entrypoint for an application, or included via CDN in the appliaction consuming this library.
import "reflect-metadata";
Open Planet Node uses https://github.com/inversify/InversifyJS for dependency injection whish is depednent upon Reflect.