The repository contains:
- Distributed code from eCentennial:
server.js
used to build an API server. /.devcontainer
: Configuration file used by Codespaces to determine operating system./.vscode
: Configuration file used by Codespaces to configure Visual Studio Code settings.package.json
andyarn.lock
: Defines the application information for Node.js, dependent packages, and the versions needed for each.
This is a simple Express application that manages a list of items. It supports basic CRUD operations through a RESTful API:
- Retrieve all items
- Retrieve a items by ID
- Add a new item
- Edit an existing item by ID
- Delete a item by ID
Select Open in GitHub Codespaces and then Create codespace. GitHub will prepare the development environment.
Install the necessary dependencies.
yarn
After installing the packages, start the server:
yarn start
-
Open Thunder Client:
- Open Thunder Client readily installed in Codespaces by clicking on its icon on the sidebar.
-
Create a New Request:
- In Thunder Client, click on the New Request button to start setting up the API request.
- Enter the API endpoint URL in the URL field:
http://localhost:8080/api/items
. - Select the HTTP method
POST
from the dropdown next to the URL field.
-
Set Up Request Body:
- Click on the "Body" tab, choose and enter the JSON data:
{ "sportName": "Swimming" }
-
Send the Request:
- Click the "Send" button to execute the request. Thunder Client will display the response from the API, including status code, response time, and the body.
-
URL:
/api/items
-
Method:
GET
-
Response:
[ "Soccer", "Handball", "Volleyball", "Cricket", "Swimming" ]
-
URL:
/api/items/:itemId
-
Method:
GET
-
URL Params:
itemId
- ID of the sport
-
Response:
{ "sportName": "Volleyball" }
-
URL:
/api/items
-
Method:
POST
-
Body:
{ "sportName": "Basketball" }
-
Response:
{ "message": "Added Basketball as item identifier 5" }
-
URL:
/api/items/:id
-
Method:
PUT
-
URL Params:
id
- ID of the sport
-
Body:
{ "sportName": "Rugby" }
-
Response:
{ "message": "Updated item with identifier: 0 to Rugby" }
-
URL:
/api/items/:id
-
Method:
DELETE
-
URL Params:
id
- ID of the sport
-
Response:
{ "message": "Deleted sport: Volleyball" }