Skip to content

Latest commit

 

History

History
233 lines (152 loc) · 3.38 KB

File metadata and controls

233 lines (152 loc) · 3.38 KB

Coinserver

A NodeJS/Express REST API that serves up coin flips

This was developed from in-class demos for UNC COMP 426 Spring 2022.

Install and run instructions

This currently works on Node v16.x.x (current iteration developed on v16.15.0).

To install, clone this repository and then run npm install inside the directory. This will install all dependencies.

To run for debugging, run npm test. It will listen on port 5555.

To run, use npm start and the server will listen on whatever port is configured in .env or default to 5000.

To run on a specific port either change PORT= in .env or use node index.js --port=PORT_NUMBER.

node index.js --help shows all currently-implemented options.

Coinserver API Documentation

Endpoints

/app/

Responds "200 OK"

Response body

curl http://localhost:5000/app/
{"message":"Your API works! (200)"}

Headers

curl -I http://localhost:5000/app/
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 35
ETag: W/"23-KNmhzXgQhtEE5ovS3fuLixylNK0"
Date: Thu, 28 Apr 2022 23:57:37 GMT
Connection: keep-alive
Keep-Alive: timeout=5

/app/flip/

Response body

curl http://localhost:5000/app/flip/
{"flip":"tails"}

/app/flips/:number/

Response body

curl http://localhost:5000/app/flips/4
{"raw":["tails","heads","heads","heads"],"summary":{"tails":1,"heads":3}}

/app/flip/call/

Request body

{"call":"(heads|tails)"}

Response body

curl -X POST -d '{"guess":"tails"}' -H 'Content-Type: application/json' http://localhost:5000/app/flip/call/
{"call":"tails","flip":"tails","result":"win"}

/app/flip/call/:guess(heads|tails)/

Response body

curl http://localhost:5000/app/flip/call/heads
{"call":"tails","flip":"tails","result":"win"}

/app/flip/coins/

Request body

{"number":"(\d)"}

Response body

curl -X POST -d '{"number":"5"}' -H 'Content-Type: application/json' http://localhost:5000/app/flip/coins/
{"raw":["heads","heads","heads","tails","tails"],"summary":{"heads":3,"tails":2}}

/app/log/access/

Response body

curl http://localhost:5000/app/log/access
[{"id":1,"remoteaddr":"::1","remoteuser":null,"time":"1651190213738.0","method":"GET","url":"/","protocol":"http","httpversion":"1.1","status":"200.0","referrer":null,"useragent":"curl/7.74.0"},{"id":2,"remoteaddr":"::1","remoteuser":null,"time":"1651190219236.0","method":"GET","url":"/app/","protocol":"http","httpversion":"1.1","status":"200.0","referrer":null,"useragent":"curl/7.74.0"}]

/app/log/error/

Not yet implemented

Response body

/app/login/

Not yet implemented

Request body

Response body

Headers


/app/user/login/

Not yet implemented

Request body

Response body

Headers


/app/user/new/

Not yet implemented

Request body

Response body

Headers


/app/user/update/

Not yet implemented

Request body

Response body

Headers


/app/user/delete/

Not yet implemented

Request body

Response body

Headers