I built a web server with Node.js/Express on top of AWS EC2.
The application returns a response to the GET request from the client.
This project was part of Amazon Cloud Engineer Technical Test.
-
/returnsAMAZONif request was successful (Below is a sample IP address)- run
$ curl "http://1.2.3.4/"
- run
-
/secretvalidates basic authentiation with{ login: 'amazon', password: 'candidate' }- running
$ curl -u amazon:candidate "http://1.2.3.4/secret/", returnsSUCCESS - running
$ curl "http://1.2.3.4/secret/", returns authentication fail message
- running
-
/calc- running
$ curl 'http://1.2.3.4/calc?1+2*3', returns 7 - running
$ curl 'http://1.2.3.4/calc?2-1', returns 1 - running
$ curl 'http://1.2.3.4/calc?3*2', returns 6
- running
-
/stocker- running below returns
xxx: 96
$ curl "http://1.2.3.4:8080/stocker?function=deleteall" $ curl "http://1.2.3.4:8080/stocker?function=addstock&name=xxx&amount=100" $ curl "http://1.2.3.4:8080/stocker?function=sell&name=xxx&amount=4" $ curl "http://1.2.3.4:8080/stocker?function=checkstock&name=xxx"- running below returns
xxx: 96 yyy: 100 YYY: 100
$ curl "http://1.2.3.4:8080/stocker?function=addstock&name=yyy&amount=100" $ curl "http://1.2.3.4:8080/stocker?function=addstock&name=YYY&amount=100" $ curl "http://1.2.3.4:8080/stocker?function=checkstock" - running below returns
Below are the functions implemented for /stocker
(1) Addition of inventory
- argument:
- function (required): addstock
- name (required): Specify the name of the target product.
- amount (arbitrary): Specify the number (positive integer) to add the target product to the inventory. The default is 1.
- Output: None
(2) Inventory check
- argument:
- function (required): checkstock
- name (optional): Specify the name of the target product.
- Output:
- If a name is specified, the number of items in stock with that name is output in the "[name]: [amount]" format. When there is no stock, amount is displayed as 0.
- When name is not specified, the number of stocks of all products is sorted in ascending order with name as a key and output. Items with 0 inventory are not displayed.
- Example output:
- xxx: 12
- yyy: 7
(3) Sales
-
argument:
- function (required): sell
- name (required): Specify the name of the target product.
- amount (arbitrary): Specify the number (a positive integer) of the target product sold. The default is 1.
- price (optional): Specify the price of the target product (a number greater than 0). Only when input, add price x amount to sales.
-
Output: None
(4) Sales check
- argument:
-
function (required): checksales
-
Output: Displays the current sales in the format "sales: [sales]". For decimal numbers, round up to the second decimal place.
-
- Example output:
- sales: 400
(5) Delete all
-
argument:
- function (required): deleteall
-
Output: None
It was my first time connecting to a remote computer through SSH.
I learned how to use vim, and play around with requests and responses over HTTP.
- Please replace the IP address on
app.js, with your IP address to run on localhost. - run
node app.jsto start the web server