For my first app using Mongo, NodeJS and ExpressJS i've revisited a previous Django app to provide UK postcode data.
The purpose of this service is as a demo / introduction to these technologies. With 1.7 million postcodes this app appears to suit the abilities (especially MongoDB Geo functions) of Mongo.
Results are returned from the database in the form of JSON, for example:
[
{
"_id": "505ca7db6df52eccbce59c94",
"easting": 352835,
"loc": {
"lon": -2.7378499507904053,
"lat": 54.94620132446289
},
"northing": 561533,
"postcode": "CA81DW"
}
]
Currently there are the following methods:
Postcodes Near
http://postcodes.signalfire.co.uk:8080/postcodes/near
Returns the postcodes nearest to the longitude and latitude provided
Query string parameters include:
| Parameter | Description | Default |
|---|---|---|
| latitude | Latitude of point | Defaults to 51.499612 |
| longitude | Longitude of point | Defaults to -0.135738 |
| distance | Distance from point | Defaults to 5 miles |
| limit | Limit resultset | Defaults to 10 results |
Postcodes Get
http://postcodes.signalfire.co.uk:8080/postcodes/get
Get a single postcode longitude and latitude
Query string parameters include:
| Parameter | Description | Default |
|---|---|---|
| postcode | Postcode to lookup | Defaults to W1A1AA |
Example:
http://postcodes.signalfire.co.uk/postcodes/get?postcode=W1A1AA
Postcodes Box
http://postcodes.signalfire.co.uk:8080/postcodes/box
Get postcode longitudes and latitudes within a box
Query string parameters include:
| Parameter | Description | Default |
|---|---|---|
| latitude1 | First latitude | Defaults to 51.499612 |
| longitude1 | First longitude | Defaults to -0.135738 |
| latitude2 | Second latitude | Defaults to 51.483641 |
| longitude2 | Second longitude | Defaults to -0.115433 |
| limit | Limit resultset | Defaults to 10 results |
Postcodes Circle
http://postcodes.signalfire.co.uk:8080/postcodes/circle
Get postcode longitudes and latitudes within a circle
Query string parameters include:
| Parameter | Description | Default |
|---|---|---|
| latitude | Latitude of point | Defaults to 51.499612 |
| longitude | Longitude of point | Defaults to -0.135738 |
| radius | Radius to search | Defaults to 5 |
| limit | Limit resultset | Defaults to 10 results |
The service doesn't currently have any authentication or authorisation so you are free to use (as long as your use doesn't kill my server). I will add some additional functionality later, but as a quick nodejs + expressjs and mongodb project its been interesting how quickly it came together.