2nd homework assignment for Pirple's NodeJS master class. This project is a JSON RESTful dependency-free API for a pizza-delivery company utilizing Stripe and MailGun external services.
JavaScript
Crazy Pizza API
2nd homework assignment for Pirple's NodeJS master class.
This project is a JSON RESTful API free of 3rd-party dependencies for a pizza-delivery company utilizing Stripe and MailGun external services.
ROUTES
USERS
Method
Header
Query params
Payload
Desc
GET
token*
email*
Return information about the user except for password in a JSON format.
PUT
token*
email*, at least one of: (firstName, lastName, password)*
Change one/more of user's information. Email change not allowed.
With extend set to true, a valid token's lifespan is extended.
POST
email*, password*
Log in. Return a new, valid token for the user to use with other routes.
DELETE
id*
Log out.
MENU
Method
Header
Query params
Payload
Desc
GET
token*
Get menu as a JSON array of pizzas.
SHOPPINGCART
Method
Header
Query params
Payload
Desc
GET
token*
Get full list of existing, unpurchased orders for the user.
POST
token*
array of items*, eg. [{"id":1,"amount":2}]
Save an order to the shopping cart. amount field in the item is optional. If not supplied, it's set to 1.
DELETE
token*
orderid*
Delete an order from user's shopping cart.
PURCHASE
Method
Header
Query params
Payload
Desc
POST
token*, orderId
array of items, eg. [{"id":1,"amount":2}]
If orderId header is set, the order is loaded from user's shopping cart. If payload is populated (just as in POST for SHOPPINGCART route), the order is loaded from it. If both are set, orderId precedes. If the payment is successful, a receipt is emailed.
*Required
Manual
Set up
Download the project.
Open the command prompt (for Windows, click Start icon and type in 'cmd') and go to the project directory.eg. :
cd C:/HelloAPI
Run the app:
node index.js
Optionally, one can set the environment as command line argument (with value of 'production' or 'staging'). The default is 'staging'.
node index.js production (for Windows)
NODE_ENV=production node index.js (for Linux)
The app informs which ports are active.
Open up a web browser or a tool like Postman. Start making requests. Follow the Basic scenario below to learn the most useful requests.
Push Ctrl + C to stop the app.
Basic scenario:
Create a user. (USERS, POST)
Log in. (TOKENS, POST)
View menu. (MENU, GET)
Order a pizza. (SHOPPINGCART, POST)
Pay for the order. (PURCHASE, POST)
Check email for a receipt.
Log out. (TOKENS, DELETE)
Please populate the fields in your request according to the ROUTE tables above. Required fields are marked with *.
API functionalities by route
Users
Create a user (an account).
Get user's data.
Update user's data.
Delete a user (an account).
Tokens
Create a token (log into an account).
Get token's data (expiration date and time).
Extend token's expiration date.
Delete a token (log out).
Menu
Get the menu.
Shopping cart
Create an order (select items from menu).
List existing orders (items chosen but not yet purchased).