A NodeJS/Express REST API that serves up coin flips
This was developed from in-class demos for UNC COMP 426 Spring 2022.
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.
Responds "200 OK"
curl http://localhost:5000/app/
{"message":"Your API works! (200)"}
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
curl http://localhost:5000/app/flip/
{"flip":"tails"}
curl http://localhost:5000/app/flips/4
{"raw":["tails","heads","heads","heads"],"summary":{"tails":1,"heads":3}}
{"call":"(heads|tails)"}
curl -X POST -d '{"guess":"tails"}' -H 'Content-Type: application/json' http://localhost:5000/app/flip/call/
{"call":"tails","flip":"tails","result":"win"}
curl http://localhost:5000/app/flip/call/heads
{"call":"tails","flip":"tails","result":"win"}
{"number":"(\d)"}
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}}
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"}]
Not yet implemented
Not yet implemented
Not yet implemented
Not yet implemented
Not yet implemented
Not yet implemented