Getting started with example queries using Node.js
This page provides example queries that you can adapt and use with OS Names API. The examples use Node.js the popular axios module.
What you need
OS Names API added to an API project in the OS Data Hub with an API Key. See Getting started with an API project for more information.
A text editor like Visual Studio Code
Example queries using Node.js
Running a find
query
find
queryconst axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
async function find() {
axios.get('https://api.os.uk/search/names/v1/find?query=Southampton&key=' + apiKey)
.then(function (response) {
/* For explanation and debugging purposes we display the full response from the API in the console */
console.log(JSON.stringify(response.data, null, 2));
});
}
find()
Running a nearest
query.
nearest
query.const axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
async function nearest() {
axios.get('https://api.os.uk/search/names/v1/nearest?point=440200,449300&key=' + apiKey)
.then(function (response) {
/* For explanation and debugging purposes we display the full response from the API in the console */
console.log(JSON.stringify(response.data, null, 2));
});
}
nearest()
Last updated
Was this helpful?