API backend server for the Sjekk UT mobile application.
From the Old Norse Verðandi meaning "becoming, happening". Verdandi was one of the three Norns, or goddesses of destiny, in Norse mythology. She was responsible for the present.
Thence come maidens
much knowing
three from the hall
which under that tree stands;
Urd hight the one,
the second Verdandi,
on a tablet they graved,
Skuld the third;
Laws they established,
life allotted
to the sons of men,
destinies pronounced.
Getting started
Download Docker for Mac or Windows.
Run in this directory:
$ docker-compose up
Test
docker-compose run --rm node npm run test
docker-compose run --rm node npm run lint
Environment variables
CHECKIN_MAX_DISTANCE=200
- Used to validate a users proximity to the coordinates it's checking in to. Distance in meters.CHECKIN_TIMEOUT=86400
- Used to validate that a user is not checking in to the same place more often than this timeout allows. Time in seconds.
API
Authentication
Some API endpoints requires the following user authentication headers:
X-User-Id
- DNT Connect User IDX-User-Token
- DNT Connect OAuth 2 token
Response codes
Unless otherwise statet API endpoints will return the following HTTP status codes:
200 Ok
- Successfull GET request201 Created
- Successfull POST or PUT request204 No Content
- Successfull HEAD or DELETE request400 Bad Request
- Bad user supplied data401 Unauthorized
- Missing or invalid user authentication403 Forbidden
- Missing or invalid user permissions404 Not Found
- Resource or endpoint not found500 Internal Server Error
- Internal server error501 Not Implemented
- API endpoint is not implemented yet
GET /v2/
Status codes:
Returns 200 Ok
and an API index on successfull request.
GET body:
- number
checkin_new.rules.max_distance
- Max distance in meters a user can have to the place it is checking in to. - number
checkin_new.rules.quarantine
- A user can not check in twice to the same place within this period. Time in seconds.
Example:
GET /v2 HTTP/1.1Accept: application/json HTTP/1.1 OkContent-Type: application/json { "checkin_new": { "url": "https://sjekkut.app.dnt.no/api/v2/steder/{sted}/besok", "rules": { "max_distance": 200, "quarantine": 86400 } }, "checkin_get": { "url": "https://sjekkut.app.dnt.no/api/v2/steder/{sted}/besok/{oid}" }, "checkin_log": { "url": "https://sjekkut.app.dnt.no/api/v2/steder/{sted}/logg" }, "checkin_stats": { "url": "https://sjekkut.app.dnt.no/api/v2/steder/{sted}/stats" }, "profile_view": { "url": "https://sjekkut.app.dnt.no/api/v2/brukere/{bruker}" }, "list_join": { "url": "https://sjekkut.app.dnt.no/api/v2/lister/{liste}/blimed" }, "list_leave": { "url": "https://sjekkut.app.dnt.no/api/v2/lister/{liste}/meldav" }, "list_log": { "url": "https://sjekkut.app.dnt.no/api/v2/lister/{liste}/logg" }}
GET /v2/steder/{sted}/stats
Status codes:
Returns 200 Ok
on successfull request.
Example:
GET /v2/steder/524081f9b8cb77df15001660/stats HTTP/1.1Accept: application/json HTTP/1.1 OkContent-Type: application/json { "data": { "count": 2, }}
GET /v2/steder/{sted}/logg
Status codes:
Returns 200 Ok
on successfull request.
Example:
GET /v2/steder/524081f9b8cb77df15001660/logg HTTP/1.1Accept: application/json HTTP/1.1 OkContent-Type: application/json { "data": [ {...}, {...} ]}
POST /v2/steder/{sted}/besok
Status codes:
201 Created
on successfull checkin.400 Bad Request
on validation error.
POST body:
- number
lat
- decimal latitude (required) - number
lon
- decimal longitude (required) - boolean
public
- (defaultfalse
) - string
timestamp
- date and time ISO 8601 (defaultDate.now()
)
Example:
POST /v2/steder/524081f9b8cb77df15001660/besok HTTP/1.1Accept: application/jsonX-User-Id: 123X-User-Token asdf123 { "lat": 12.3456, "lon": 98.7654, "public": true, "timestamp": "2016-09-06T12:27:21.594Z"} HTTP/1.1 201 CreatedContent-Type: application/jsonLocation: /v2/steder/524081f9b8cb77df15001660/besok/1234-123-123-1234 { "message": "Ok", "data": {...}}
GET /v2/steder/{sted}/besok/{oid}
Status codes:
Returns 200 Ok
for valid checkin.
Example:
GET /v2/steder/524081f9b8cb77df15001660/besok/1234-123-123-1234 HTTP/1.1Accept: application/json HTTP/1.1 200 OkContent-Type: application/json { "data": {...}}
GET /v2/brukere/{bruker}
Status codes:
Returns 200 Ok
on successfull request.
Example:
GET /v2/brukere/1234 HTTP/1.1Accept: application/json HTTP/1.1 OkContent-Type: application/json { "data": {...}}
POST /v2/lister/{liste}/blimed
Add the list id to current user's lister
array.
Status codes:
Returns 200 Ok
on successfull request.
Example:
POST /v2/lister/300000000000000000000001/blimed HTTP/1.1Accept: application/json HTTP/1.1 OkContent-Type: application/json { "message": "Ok", "data": {...}}
POST /v2/lister/{liste}/meldav
Remove the list id from current user's lister
array.
Status codes:
Returns 200 Ok
on successfull request.
Example:
POST /v2/lister/300000000000000000000001/meldav HTTP/1.1Accept: application/json HTTP/1.1 OkContent-Type: application/json { "message": "Ok", "data": {...}}
GET /v2/lister/{liste}/logg
Status codes:
Returns 200 Ok
on successfull request.
Example:
GET /v2/lister/57974036b565590001a98884/logg HTTP/1.1Accept: application/json HTTP/1.1 OkContent-Type: application/json { "data": [ {...}, {...} ]}