Skip to content

A NodeJS/Express REST API that serves up coin flips

License

Notifications You must be signed in to change notification settings

jdmar3/coinserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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


About

A NodeJS/Express REST API that serves up coin flips

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published