mirror of https://github.com/pelias/api.git
Diana Shkolnikov
10 years ago
19 changed files with 364 additions and 45 deletions
@ -1,2 +1,5 @@ |
|||||||
node_modules |
node_modules |
||||||
*.log |
coverage |
||||||
|
.idea |
||||||
|
*.log |
||||||
|
reports |
@ -0,0 +1,114 @@ |
|||||||
|
## /search |
||||||
|
|
||||||
|
Full text search endpoint which queries the elasticsearch doc store, slightly slower than suggest. |
||||||
|
|
||||||
|
#### Required Parameters |
||||||
|
* **input**: query string |
||||||
|
|
||||||
|
#### Optional Parameters |
||||||
|
* **lat**: latitude |
||||||
|
* **lon**: longitude |
||||||
|
* **zoom**: zoom level from which you wish to view the world |
||||||
|
* **size**: number of results requested (defaults to 10) |
||||||
|
* **layers**: datasets you wish to query (defaults to ```poi,admin,address```). |
||||||
|
* valid values are ```poi```, ```admin``` or ```address``` |
||||||
|
* ```poi``` expands internally to ```geoname```, ```osmnode```, ```osmway``` |
||||||
|
* ```admin``` expands to ```admin0```, ```admin1```, ```admin2```, ```neighborhood```, ```locality```, ```local_admin``` |
||||||
|
* ```address``` expands to ```osmaddress```, ```openaddresses``` |
||||||
|
* can also be specific to one particular dataset, for example ```geoname``` |
||||||
|
* **bbox**: the bounding box from which you want all your results to come |
||||||
|
* can be one of the following comma separated string values |
||||||
|
* bottom left lat, bottom left lon, top right lat, top right lon |
||||||
|
* left, bottom, right, top |
||||||
|
* min longitude, min latitude, max longitude, max latitude |
||||||
|
|
||||||
|
|
||||||
|
## /search/coarse |
||||||
|
|
||||||
|
This is a coarse forward geocoder endpoint which only searches admin dataset layers. |
||||||
|
|
||||||
|
#### Required Parameters |
||||||
|
* **input**: query string |
||||||
|
|
||||||
|
#### Optional Parameters |
||||||
|
* **lat**: latitude |
||||||
|
* **lon**: longitude |
||||||
|
* **zoom**: zoom level from which you wish to view the world |
||||||
|
* **bbox**: the bounding box frome which you want all your results to come |
||||||
|
* **size**: (defaults to 10) |
||||||
|
* **layers**: (defaults to ```admin```) |
||||||
|
|
||||||
|
|
||||||
|
## /suggest |
||||||
|
|
||||||
|
The autocomplete endpoint, it offers fast response time. Mixes results from around the provided lat/lon and also from precision level 1 and 3. |
||||||
|
|
||||||
|
#### Required Parameters |
||||||
|
* **input**: query string |
||||||
|
* **lat**: latitude |
||||||
|
* **lon**: longitude |
||||||
|
* lat/lon are **required** currently because of this [open issue](https://github.com/elasticsearch/elasticsearch/issues/6444) |
||||||
|
|
||||||
|
#### Optional Parameters |
||||||
|
* **zoom**: zoom level from which you wish to view the world |
||||||
|
* **size**: number of results requested (defaults to 10) |
||||||
|
* **layers**: datasets you wish to query (defaults to ```poi,admin,address```) |
||||||
|
|
||||||
|
|
||||||
|
## /suggest/coarse |
||||||
|
|
||||||
|
Only queries the admin layers. |
||||||
|
|
||||||
|
#### Required Parameters |
||||||
|
* **input**: query string |
||||||
|
* **lat**: latitude from where you are searching |
||||||
|
* **lon**: longitude |
||||||
|
* lat/lon are **required** currently because of this [open issue](https://github.com/elasticsearch/elasticsearch/issues/6444) |
||||||
|
|
||||||
|
#### Optional Parameters |
||||||
|
* **zoom**: zoom level from which you wish to view the world |
||||||
|
* **size**: number of results requested (defaults to 10) |
||||||
|
* **layers**: datasets you wish to query (defaults to ```admin```) |
||||||
|
|
||||||
|
|
||||||
|
## /suggest/nearby |
||||||
|
|
||||||
|
Works as autocomplete for places located near a latitude/longitude, this endpoint is the same as ```/suggest``` but the results are all from within 50 kilometers of the specified point. Unlike ```/suggest```, ```/suggest/nearby``` does not mix results from different precision levels (500km, 1000km etc from lat/lon). |
||||||
|
|
||||||
|
#### Required Parameters |
||||||
|
* **input**: query string |
||||||
|
* **lat**: latitude |
||||||
|
* **lon**: longitude |
||||||
|
* lat/lon are **required** currently because of this [open issue](https://github.com/elasticsearch/elasticsearch/issues/6444) |
||||||
|
|
||||||
|
#### Optional Parameters |
||||||
|
* **zoom**: zoom level from which you wish to view the world |
||||||
|
* **size**: number of results you need (defaults to 10) |
||||||
|
* **layers**: datasets you wish to query (defaults to ```poi,admin,address```) |
||||||
|
|
||||||
|
|
||||||
|
## /reverse |
||||||
|
|
||||||
|
Reverse geocoding endpoint. |
||||||
|
|
||||||
|
#### Required Parameters |
||||||
|
* **lat**: latitude |
||||||
|
* **lon**: longitude |
||||||
|
|
||||||
|
#### Optional Parameters |
||||||
|
* **zoom**: zoom level from which you wish to view the world |
||||||
|
* **bbox**: bounding box |
||||||
|
* **layers**: (defaults to ```poi,admin,address```) |
||||||
|
|
||||||
|
|
||||||
|
## /doc |
||||||
|
|
||||||
|
Retrieves a document or multiple documents at once. |
||||||
|
|
||||||
|
#### Required Parameters |
||||||
|
* one of **id** or **ids** |
||||||
|
* **id**: |
||||||
|
* unique id of the document to be retrieved |
||||||
|
* should be in the form of type:id, for example: ```geoname:4163334``` |
||||||
|
* **ids**: |
||||||
|
* if multiple docs are to be fetched in bulk, an array of ids |
@ -1,22 +1,31 @@ |
|||||||
|
|
||||||
var pkg = require('../package'); |
var pkg = require('../package'); |
||||||
|
var markdown = require('markdown').markdown; |
||||||
|
var fs = require('fs'); |
||||||
|
|
||||||
function setup(){ |
function setup(){ |
||||||
|
|
||||||
function controller( req, res, next ){ |
var styleString = '<style>html{font-family:monospace}</style>'; |
||||||
|
var text = '# Pelias API\n'; |
||||||
// stats
|
text += '### Version: ['+ pkg.version+ '](https://github.com/pelias/api/releases)\n'; |
||||||
|
text += fs.readFileSync( './DOCS.md', 'utf8'); |
||||||
|
var indexHtml = styleString + markdown.toHTML(text); |
||||||
|
|
||||||
|
function controller( req, res, next ) { |
||||||
|
if (req.accepts('html')) { |
||||||
|
res.send(indexHtml); |
||||||
|
return; |
||||||
|
} |
||||||
|
// default behaviour
|
||||||
res.json({ |
res.json({ |
||||||
name: pkg.name, |
name: pkg.name, |
||||||
version: { |
version: { |
||||||
number: pkg.version |
number: pkg.version |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
return controller; |
return controller; |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
module.exports = setup; |
module.exports = setup; |
||||||
|
@ -1,9 +1,12 @@ |
|||||||
|
var logger = require( '../src/logger' ); |
||||||
|
|
||||||
// handle application errors
|
// handle application errors
|
||||||
function middleware(err, req, res, next) { |
function middleware(err, req, res, next) { |
||||||
|
logger.error( 'Error:', err ); |
||||||
|
logger.error( 'Stack trace:', err.trace ); |
||||||
res.header('Cache-Control','no-cache'); |
res.header('Cache-Control','no-cache'); |
||||||
if( res.statusCode < 400 ){ res.status(500); } |
if( res.statusCode < 400 ){ res.status(500); } |
||||||
res.json({ error: err }); |
res.json({ error: 'internal server error' }); |
||||||
} |
} |
||||||
|
|
||||||
module.exports = middleware; |
module.exports = middleware; |
||||||
|
@ -0,0 +1,38 @@ |
|||||||
|
|
||||||
|
var isObject = require('is-object'); |
||||||
|
|
||||||
|
// validate inputs, convert types and apply defaults
|
||||||
|
function sanitize( req ){ |
||||||
|
|
||||||
|
var clean = req.clean || {}; |
||||||
|
var params= req.query; |
||||||
|
|
||||||
|
// ensure the input params are a valid object
|
||||||
|
if( !isObject( params ) ){ |
||||||
|
params = {}; |
||||||
|
} |
||||||
|
|
||||||
|
// default case (no categories specified in GET params)
|
||||||
|
if('string' !== typeof params.categories || !params.categories.length){ |
||||||
|
clean.categories = []; |
||||||
|
} |
||||||
|
else { |
||||||
|
// parse GET params
|
||||||
|
clean.categories = params.categories.split(',') |
||||||
|
.map(function (cat) { |
||||||
|
return cat.toLowerCase().trim(); // lowercase inputs
|
||||||
|
}) |
||||||
|
.filter( function( cat ) { |
||||||
|
return ( cat.length > 0 ); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
// pass validated params to next middleware
|
||||||
|
req.clean = clean; |
||||||
|
|
||||||
|
return { 'error': false }; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
// export function
|
||||||
|
module.exports = sanitize; |
@ -1,10 +0,0 @@ |
|||||||
|
|
||||||
#> jsonp |
|
||||||
path: '/?callback=test' |
|
||||||
|
|
||||||
#? content-type header correctly set |
|
||||||
response.should.have.header 'Content-Type','application/javascript; charset=utf-8' |
|
||||||
|
|
||||||
#? should respond with jsonp |
|
||||||
should.exist response.body |
|
||||||
response.body.substr(0,5).should.equal 'test('; |
|
Loading…
Reference in new issue