Code for Kata 5 is available in the app5 folder.
Up to now all data manipulation used the data.js
file to focus on frontend work.
We are now moving the data to a backend server in aspnet core.
The idea here is to learn how a web app can interact with a backend server through REST API calls.
You will need 2 terminals
-
Web API server
- go to
./app5
- verify dotnet version
dotnet --version
is2.0.0
- run
dotnet restore
- run
dotnet build
- run
dotnet run
This should build the web api server and serve it at
http:\\localhost:5000
- go to
-
Web app
- in another terminal
- go to
./app5/app/
- follow the instructions in the README.
- your app should be running at port 3000
You are given a server that exposes the following REST
endpoints.
description | method | api call | notes |
---|---|---|---|
list all products | GET |
http:localhost:5000/api/products/get |
|
delete product | DELETE |
http:localhost:5000/api/products/delete/readyroll |
|
add product | POST |
http:localhost:5000/api/products/add |
json/application with body {name: 'product1', description: 'product description here'} |
Notes:
- There is a proxy between the web server(port
5000
) and the app server (port3000
) so that in the app you can use/api/products/get
. This then gets resolved tolocalhost:5000/api/products/get
behind the scenes. delete
andadd
api calls return the list of products so that you can update the products data right away instead of calling/api/products/get
again.
Write the JavaScript/React code to:
- List all products in the homepage when the app is loaded using the REST api.
- you can use technologies like fetch or jQuery.ajax
- to add a package do yarn add
- eg:
yarn add whatwg-fetch
- after this you should be able to
- Navigate to each product page
- Have hard links on products names
- Add a remove button so that the user can remove a product from the list.
- you should use the REST api for this,
/api/products/delete/productname
(see above for details)
- you should use the REST api for this,
- Add a form so that user is able to add a new product to the list.
- you should use the REST api for this
/api/products/add
(see above for details)
- you should use the REST api for this
- Changes to the data should persist through sessions:
- delete a product
- add a new product
- open a new tab with the app
- verify the removed product is not present
- verify the added product is present