In this task, you will create a banking API with the basic CRUD
operations.
- Fork and clone this repository to your
Development
folder.
- You have a data file called
accounts.js
, it's an array of bank accounts with the owner's username and the funds that he got in KWD.
- The method you will use is
get
, create a route to/accounts
. - In the response, send the
accounts
data, using thejson
method because we need to convert it tojson
. - We need to also send a status code using
.status
method, which code represents a successful response?
- The method you will use is
post
, create a route to/accounts
. - Generate an
id
for our new account. - Create a variable
newAccount
to store our new account, pass it the data coming fromreq.body
, theid
we just created and a funds of 0 since it's the default - Push your
newAccount
into theaccounts
array. - Return the
newAccount
in the response with the correct status code.
- The method you will use is
delete
, create a route to/accounts
that accepts a paramaccountId
. - Extract this param using
req.params
. - Find the account with the same
id
, if it doesn't exist, return a response with404
status code andnot found
message. - If it does exist, filter your
accounts
array to not incldue this deleted account. - Send a response with the correct status code.
- The method you will use is
put
, create a route to/accounts
that accepts a paramaccountId
. - Extract this param using
req.params
. - Find the account with the same
id
, if it doesn't exist, return a response with404
status code andnot found
message. - If it does exist, replace the values of the account with the new values coming from the
req
. - Send a response with the correct status code.
- Create a route that retrieve a single account by the username of the owner not by it's ID.
You have learned about route params, but there's also something called query params.
- On the route you created in the previous challenge, add a query param that retrieves the account info and funds in USD.
Your URL should look like:
localhost:8000/accounts/Omar?currency=usd