How To Test
This guide provides instructions on how to test the GreenWave API using Postman. It covers setting up the environment, configuring authorization, and constructing requests.
Prerequisites
- Download and install Postman.
- Ensure the backend server is running and accessible.
1. Environment Setup
Using environments in Postman allows you to switch between different setups (e.g., Local, Development, Production) easily without changing the request URLs manually.
- Open Postman and go to the Environments tab on the left sidebar.
- Click Create Environment.
- Name the environment (e.g.,
GreenWave Local). - Add the following variable:
| Variable | Type | Initial Value | Current Value |
|---|---|---|---|
baseUrl | Default | http://localhost:8000 | http://localhost:8000 |
- Click Save.
- Select this environment from the environment dropdown in the top right corner.
2. Authorization
If the API requires authentication, configure it at the Collection level so it applies to all requests.
- Create a new Collection in Postman (e.g.,
GreenWave API). - Select the Collection and go to the Authorization tab.
- Select the appropriate Type (e.g., Bearer Token or API Key).
- Enter your token or key.
- If using a variable, enter
{{authToken}}in the Token field and addauthTokento your Environment variables.
- If using a variable, enter
- Click Save.
3. Constructing Requests
When creating requests, use the {{baseUrl}} variable followed by the specific endpoint path.
GET Request
Used to retrieve data.
Example: Query AirQualityObserved Entities
- Create a new request.
- Set the method to GET.
- Enter the URL:
{{baseUrl}}/api/v1/air-quality - Params (Optional): Add query parameters to filter results.
- Key:
limit, Value:10 - Key:
format, Value:keyValues
- Key:
- Click Send.
POST Request
Used to create new entities. Requires a JSON body.
Example: Create AirQualityObserved Entity
- Create a new request.
- Set the method to POST.
- Enter the URL:
{{baseUrl}}/api/v1/air-quality - Go to the Body tab.
- Select raw and choose JSON from the dropdown.
- Enter the JSON payload:
{
"id": "urn:ngsi-ld:AirQualityObserved:001",
"type": "AirQualityObserved",
"dateObserved": {
"type": "Property",
"value": "2023-10-01T12:00:00Z"
},
"NO2": {
"type": "Property",
"value": 45
},
"location": {
"type": "GeoProperty",
"value": {
"type": "Point",
"coordinates": [-3.70379, 40.416775]
}
}
}
- Click Send.
PATCH Request
Used to update existing entities partially.
Example: Update Entity Attributes
- Create a new request.
- Set the method to PATCH.
- Enter the URL:
{{baseUrl}}/api/v1/air-quality/urn:ngsi-ld:AirQualityObserved:001/attrs - Go to the Body tab.
- Select raw and choose JSON.
- Enter the JSON payload (NGSI-LD Attribute Patch):
{
"NO2": {
"type": "Property",
"value": 50
}
}
- Click Send.
DELETE Request
Used to remove entities.
Example: Delete AirQualityObserved Entity
- Create a new request.
- Set the method to DELETE.
- Enter the URL:
{{baseUrl}}/api/v1/air-quality/urn:ngsi-ld:AirQualityObserved:001 - Click Send.
4. Batch Operations
For bulk actions, use the batch endpoints.
Example: Batch Create Entities
- Create a new request.
- Set the method to POST.
- Enter the URL:
{{baseUrl}}/api/v1/air-quality/batch/create - Body (JSON):
{
"entities": [
{
"id": "urn:ngsi-ld:AirQualityObserved:002",
"type": "AirQualityObserved",
"NO2": { "type": "Property", "value": 30 }
},
{
"id": "urn:ngsi-ld:AirQualityObserved:003",
"type": "AirQualityObserved",
"NO2": { "type": "Property", "value": 25 }
}
]
}
5. Testing Workflow Example
To verify the lifecycle of an entity, follow this sequence:
- Create: Send a POST request to create a new entity. Verify the response is
201 Createdor returns the ID. - Read: Send a GET request using the ID from the previous step. Verify the returned data matches what was sent.
- Update: Send a PATCH request to modify a property. Verify the response is
204 No Content. - Verify Update: Send a GET request again. Verify the property value has changed.
- Delete: Send a DELETE request. Verify the response is
204 No Content. - Verify Delete: Send a GET request. Verify the response is
404 Not Found.