All the global methods are exposed as a promise. This allows to chain different API-calls asynchroniously. The example below shows how you can easily get details from another API-call, while error handling is very easy and nested callbacks are prevented. The methods follow exactly the same parameters as the global exposed callback-methods, however they do not have a callback parameter (of course). When a promise is fullfiled, the promise resolved one single object with the result and the rateLimit (if requested).
The most easy way to enable the methods as promise is to add const postcodeApi = require('postcode-nl').promises;
in your code. All the functions will be exposed as promise.
- Since:
- 1.3.0
- Source:
Example
const postcodeApi = require('postcode-nl').promises;
options = {
returnRateLimit: true,
apiKey: "EcLHlMMn8M3fFbxjBIkNX6jZ1NOVlILXRQltUAg1"
}
postcodeApi.getSingleAddress(options, '0362200001001845')
.then((resolved) => {
console.log(resolved); // Result for getSingleAddress()
let postcode = resolved.result.postcode;
return postcodeApi.getSinglePostcode(options, postcode);
}).then((resolved) => {
console.log(resolved); // Result for getSinglePostcode()
}).catch((error) => {
console.log(error); // Handle errors for both calls
});
Methods
(static) getAddresses(options, query) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | See global method |
query |
Object | See global method |
- Since:
- 1.3.0
- Source:
Returns:
- When fullfiled, it returns a single object containing the objects result and rateLimit as the global method returns in the callback.
- Type
- Promise
(static) getAddressesByPostcodeAndNumber(options, query) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | See global method |
query |
Object | See global method |
- Since:
- 1.3.0
- Source:
Returns:
- When fullfiled, it returns a single object containing the objects result and rateLimit as the global method returns in the callback.
- Type
- Promise
(static) getPostcodes(options, postcodeArea) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | See global method |
postcodeArea |
Object | See global method |
- Since:
- 1.3.0
- Source:
Returns:
- When fullfiled, it returns a single object containing the objects result and rateLimit as the global method returns in the callback.
- Type
- Promise
(static) getSingleAddress(options, id) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | See global method |
id |
Object | See global method |
- Since:
- 1.3.0
- Source:
Returns:
- When fullfiled, it returns a single object containing the objects result and rateLimit as the global method returns in the callback.
- Type
- Promise
(static) getSinglePostcode(options, postcode) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | See global method |
postcode |
Object | See global method |
- Since:
- 1.3.0
- Source:
Returns:
- When fullfiled, it returns a single object containing the objects result and rateLimit as the global method returns in the callback.
- Type
- Promise