From 05fba480e9cb08b861f2ae02a707d8741ef6c4d2 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 12 Sep 2014 19:14:33 +0100 Subject: [PATCH] add docs --- docs/404.md | 65 ++++++++++++++++++ docs/cors.md | 54 +++++++++++++++ docs/index.md | 78 ++++++++++++++++++++++ docs/jsonp.md | 52 +++++++++++++++ docs/suggest/success.md | 141 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 390 insertions(+) create mode 100644 docs/404.md create mode 100644 docs/cors.md create mode 100644 docs/index.md create mode 100644 docs/jsonp.md create mode 100644 docs/suggest/success.md diff --git a/docs/404.md b/docs/404.md new file mode 100644 index 00000000..4694f1a2 --- /dev/null +++ b/docs/404.md @@ -0,0 +1,65 @@ +# invalid path + +*Generated: Fri Sep 12 2014 19:14:09 GMT+0100 (BST)* +## Request +```javascript +{ + "protocol": "http:", + "host": "localhost", + "method": "GET", + "port": 3100, + "path": "/notexist", + "headers": { + "User-Agent": "Ciao/Client 1.0" + } +} +``` + +## Response +```javascript +Status: 404 +{ + "x-powered-by": "pelias", + "charset": "utf8", + "access-control-allow-origin": "*", + "access-control-allow-methods": "GET", + "access-control-allow-headers": "X-Requested-With,content-type", + "access-control-allow-credentials": "true", + "cache-control": "public,max-age=300", + "content-type": "application/json; charset=utf-8", + "content-length": "35", + "etag": "W/\"23-dfdfa185\"", + "date": "Fri, 12 Sep 2014 18:14:09 GMT", + "connection": "close" +} +``` +```javascript +{ + "error": "not found: invalid path" +} +``` + +## Tests + +### ✓ content-type header correctly set +```javascript +response.should.have.header 'Content-Type','application/json; charset=utf-8' +``` + +### ✓ should respond in json with server info +```javascript +should.exist json +should.exist json.error +json.error.should.equal 'not found: invalid path' +``` + +### ✓ cache-control header correctly set +```javascript +response.should.have.header 'Cache-Control','public,max-age=300' +``` + +### ✓ not found +```javascript +response.statusCode.should.equal 404 +``` + diff --git a/docs/cors.md b/docs/cors.md new file mode 100644 index 00000000..77d10ea7 --- /dev/null +++ b/docs/cors.md @@ -0,0 +1,54 @@ +# cross-origin resource sharing + +*Generated: Fri Sep 12 2014 19:14:09 GMT+0100 (BST)* +## Request +```javascript +{ + "protocol": "http:", + "host": "localhost", + "method": "GET", + "port": 3100, + "path": "/", + "headers": { + "User-Agent": "Ciao/Client 1.0" + } +} +``` + +## Response +```javascript +Status: 200 +{ + "x-powered-by": "pelias", + "charset": "utf8", + "access-control-allow-origin": "*", + "access-control-allow-methods": "GET", + "access-control-allow-headers": "X-Requested-With,content-type", + "access-control-allow-credentials": "true", + "cache-control": "public,max-age=60", + "content-type": "application/json; charset=utf-8", + "content-length": "50", + "etag": "W/\"32-85536434\"", + "date": "Fri, 12 Sep 2014 18:14:09 GMT", + "connection": "close" +} +``` +```javascript +{ + "name": "pelias-api", + "version": { + "number": "0.0.0" + } +} +``` + +## Tests + +### ✓ access control headers correctly set +```javascript +response.should.have.header 'Access-Control-Allow-Origin','*' +response.should.have.header 'Access-Control-Allow-Methods','GET' +response.should.have.header 'Access-Control-Allow-Headers','X-Requested-With,content-type' +response.should.have.header 'Access-Control-Allow-Credentials','true' +``` + diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..917f36f8 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,78 @@ +# api root + +*Generated: Fri Sep 12 2014 19:14:09 GMT+0100 (BST)* +## Request +```javascript +{ + "protocol": "http:", + "host": "localhost", + "method": "GET", + "port": 3100, + "path": "/", + "headers": { + "User-Agent": "Ciao/Client 1.0" + } +} +``` + +## Response +```javascript +Status: 200 +{ + "x-powered-by": "pelias", + "charset": "utf8", + "access-control-allow-origin": "*", + "access-control-allow-methods": "GET", + "access-control-allow-headers": "X-Requested-With,content-type", + "access-control-allow-credentials": "true", + "cache-control": "public,max-age=60", + "content-type": "application/json; charset=utf-8", + "content-length": "50", + "etag": "W/\"32-85536434\"", + "date": "Fri, 12 Sep 2014 18:14:09 GMT", + "connection": "close" +} +``` +```javascript +{ + "name": "pelias-api", + "version": { + "number": "0.0.0" + } +} +``` + +## Tests + +### ✓ endpoint available +```javascript +response.statusCode.should.equal 200 +``` + +### ✓ vanity header correctly set +```javascript +response.should.have.header 'X-Powered-By','pelias' +``` + +### ✓ cache-control header correctly set +```javascript +response.should.have.header 'Cache-Control','public,max-age=60' +``` + +### ✓ should respond in json with server info +```javascript +should.exist json +should.exist json.name +should.exist json.version +``` + +### ✓ content-type header correctly set +```javascript +response.should.have.header 'Content-Type','application/json; charset=utf-8' +``` + +### ✓ charset header correctly set +```javascript +response.should.have.header 'Charset','utf8' +``` + diff --git a/docs/jsonp.md b/docs/jsonp.md new file mode 100644 index 00000000..861785cb --- /dev/null +++ b/docs/jsonp.md @@ -0,0 +1,52 @@ +# jsonp + +*Generated: Fri Sep 12 2014 19:14:09 GMT+0100 (BST)* +## Request +```javascript +{ + "protocol": "http:", + "host": "localhost", + "method": "GET", + "port": 3100, + "path": "/?callback=test", + "headers": { + "User-Agent": "Ciao/Client 1.0" + } +} +``` + +## Response +```javascript +Status: 200 +{ + "x-powered-by": "pelias", + "charset": "utf8", + "access-control-allow-origin": "*", + "access-control-allow-methods": "GET", + "access-control-allow-headers": "X-Requested-With,content-type", + "access-control-allow-credentials": "true", + "cache-control": "public,max-age=60", + "content-type": "application/javascript; charset=utf-8", + "content-length": "57", + "etag": "W/\"39-b8a2aba1\"", + "date": "Fri, 12 Sep 2014 18:14:09 GMT", + "connection": "close" +} +``` +```html +test({"name":"pelias-api","version":{"number":"0.0.0"}}); +``` + +## Tests + +### ✓ content-type header correctly set +```javascript +response.should.have.header 'Content-Type','application/javascript; charset=utf-8' +``` + +### ✓ should respond with jsonp +```javascript +should.exist response.body +response.body.substr(0,5).should.equal 'test('; +``` + diff --git a/docs/suggest/success.md b/docs/suggest/success.md new file mode 100644 index 00000000..0019f600 --- /dev/null +++ b/docs/suggest/success.md @@ -0,0 +1,141 @@ +# valid suggest query + +*Generated: Fri Sep 12 2014 19:14:09 GMT+0100 (BST)* +## Request +```javascript +{ + "protocol": "http:", + "host": "localhost", + "method": "GET", + "port": 3100, + "path": "/suggest?input=a&lat=0&lon=0", + "headers": { + "User-Agent": "Ciao/Client 1.0" + } +} +``` + +## Response +```javascript +Status: 200 +{ + "x-powered-by": "pelias", + "charset": "utf8", + "access-control-allow-origin": "*", + "access-control-allow-methods": "GET", + "access-control-allow-headers": "X-Requested-With,content-type", + "access-control-allow-credentials": "true", + "cache-control": "public,max-age=60", + "content-type": "application/json; charset=utf-8", + "content-length": "1248", + "etag": "W/\"jtfnMCXDw5frK6L5eD1thg==\"", + "date": "Fri, 12 Sep 2014 18:14:09 GMT", + "connection": "close" +} +``` +```javascript +{ + "date": 1410545649156, + "body": [ + { + "text": "ACRELÂNDIA, Brazil", + "score": 1, + "payload": { + "id": "admin2/708:adm2:br:bra:acrel__ndia", + "geo": "-66.908143,-9.954353" + } + }, + { + "text": "ALTA FLORESTA, Brazil", + "score": 1, + "payload": { + "id": "admin2/2986:adm2:br:bra:alta_floresta", + "geo": "-56.404593,-10.042071" + } + }, + { + "text": "ALTO ALEGRE, Brazil", + "score": 1, + "payload": { + "id": "admin2/4611:adm2:br:bra:alto_alegre", + "geo": "-62.627879,3.103540" + } + }, + { + "text": "ALTO PARAÍSO, Brazil", + "score": 1, + "payload": { + "id": "admin2/4584:adm2:br:bra:alto_para__so", + "geo": "-63.418743,-9.697774" + } + }, + { + "text": "ALVARÃES, Brazil", + "score": 1, + "payload": { + "id": "admin2/832:adm2:br:bra:alvar__es", + "geo": "-65.296384,-3.674615" + } + }, + { + "text": "AMAJARI, Brazil", + "score": 1, + "payload": { + "id": "admin2/4610:adm2:br:bra:amajari", + "geo": "-62.710104,3.724864" + } + }, + { + "text": "AMAZONAS, Brazil", + "score": 1, + "payload": { + "id": "admin1/3232:adm1:br:bra:amazonas", + "geo": "-64.949558,-3.785708" + } + }, + { + "text": "ANAMÃ, Brazil", + "score": 1, + "payload": { + "id": "admin2/834:adm2:br:bra:anam__", + "geo": "-61.683670,-3.473836" + } + }, + { + "text": "ANORI, Brazil", + "score": 1, + "payload": { + "id": "admin2/835:adm2:br:bra:anori", + "geo": "-62.182138,-4.154809" + } + }, + { + "text": "APIACÁS, Brazil", + "score": 1, + "payload": { + "id": "admin2/2992:adm2:br:bra:apiac__s", + "geo": "-57.803447,-8.583036" + } + } + ] +} +``` + +## Tests + +### ✓ 200 ok +```javascript +response.statusCode.should.equal 200 +``` + +### ✓ valid response +```javascript +now = new Date().getTime() +should.exist json +should.not.exist json.error +should.exist json.date +json.date.should.be.within now-1000, now+1000 +should.exist json.body +json.body.should.be.instanceof Array +``` +