In this assignment, you will build an HTML human interface for your API. You will also document your API endpoints and consider package structure.
Use the GitHub classroom link instead: https://classroom.github.com/a/PUVGxeMe
If you clone this repo directly, it will not be added to the organization as an individual repo associated with your account and you will not be able to push to it.
Full instructions for this assignment are available at: https://comp426.johndmart.in/a/05/
This package exposes endpoints and provides a web interface to emulate random chance coin flip events in the following ways:
- Flip one coin - returns result of a coin flip
- Flip many coins - returns the results of many coin flips with a summary
- Guess a coin flip and - returns the result of a flip and guess match
Run npm install
inside the package root directory.
This package was buid using Node.js LTS (16.x).
Other package dependency and version information can be found in package.json
.
node server.js [options]
--port, -p Set the port number for the server to listen on. Must be an integer
between 1 and 65535. Defaults to 5000.
--debug, -d If set to true, creates endlpoints /app/log/access/ which returns
a JSON access log from the database and /app/error which throws
an error with the message "Error test successful." Defaults to
false.
--log, -l If set to false, no log files are written. Defaults to true.
Logs are always written to database.
--help, -h Return this message and exit.
curl http://localhost:5000/app/
{"message":"Your API works! (200)"}
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, 07 Apr 2022 15:07:49 GMT
Connection: keep-alive
Keep-Alive: timeout=5
curl -X POST -H 'Content-Type: application/json' -d '{"guess":"heads"}' http://localhost:5000/app/flip/call/
{"call":"heads","flip":"heads","result":"win"}
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 46
ETag: W/"2e-U/q8iZ4JKqczXPIvtwiVRpEFlRc"
Date: Thu, 07 Apr 2022 16:30:07 GMT
Connection: keep-alive
Keep-Alive: timeout=5
curl -X POST -H 'Content-Type: application/json' -d '{"number":"30"}' http://localhost:5000/app/flip/coins/`
{"raw":["heads","heads","heads","tails","heads","heads","tails","tails","tails","heads","heads","heads","heads","heads","heads","tails","tails","heads","heads","heads","heads","heads","heads","heads","tails","heads","tails","heads","tails","heads"],"summary":{"heads":21,"tails":9}}
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 283
ETag: W/"11b-9dPTqGfngSPFEOq4loChIlpdSIE"
Date: Thu, 07 Apr 2022 15:23:35 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Not yet implemented
Not yet implemented
Not yet implemented
Not yet implemented
Not yet implemented