Introduction
This is the documentation for the Car API.
The Car API is a collection of CRUD API endpoints used to manipulate cars registered in the application.
GET http://localhost:8080/api/cars
POST http://localhost:8080/api/cars
GET http://localhost:8080/api/cars/{id}
PUT http://localhost:8080/api/cars/{id}
DELETE http://localhost:8080/api/cars/{id}
For a detailed explanation of the endpoints see below
1. GET: Get cars
Obtains a list of cars
Request
| Header | Value |
|---|---|
Content-Type |
application/json |
| Property | Value |
|---|---|
URL |
|
Method |
GET |
-
not applicable
-
not applicable
GET http://localhost:8080/api/cars
Response
Our controller’s method returns a list of cars represented as JSON
| Header | Value |
|---|---|
Content-Type |
application/json |
| HTTP Status Code | Reason |
|---|---|
200 |
OK |
The response body contains a JSON representation of the list of cars or an empty list ([])
[{
brand: "Cherly Tremblay",
licensePlate: "Thomas Fahey Jr.",
mileage: 8
},
{
brand: "Bert Lang III",
licensePlate: "Mrs. Catina Bergnaum",
mileage: 22
},
{
brand: "Ernest Kirlin Sr.",
licensePlate: "Ronnie Friesen",
mileage: 69
}]
2. POST: Create car
Create a car
Request
| Header | Value |
|---|---|
Content-Type |
application/json |
| Property | Value |
|---|---|
URL |
|
Method |
POST |
-
not applicable
The request body contains a JSON representation of the new to be created car WITHOUT the id, since the id is set by the application
POST http://localhost:8080/api/cars
{
brand: "Nova Purdy",
licensePlate: "Ross Kling",
mileage: 71
}
Response
The response body contains a JSON representation of the created car
| Header | Value |
|---|---|
Content-Type |
application/json |
| HTTP Status Code | Reason |
|---|---|
200 |
OK |
Our controller’s method returns the created car respresented as JSON WITH the id, since the id is NOW set by the application
{
id: 14249049172,
brand: "Aldo Doyle",
licensePlate: "Helaine Ritchie",
mileage: 88
}
3. GET: Get car
Obtains a specific car registered in the application by it’s unique identifier
Request
| Header | Value |
|---|---|
Content-Type |
application/json |
| Property | Value |
|---|---|
URL |
|
Method |
GET |
-
id: an Integer as the identifier of the car to be obtained
-
not applicable
GET http://localhost:8080/api/cars/3
Response
Our controller’s method returns a car represented as JSON
| Header | Value |
|---|---|
Content-Type |
application/json |
| HTTP Status Code | Reason |
|---|---|
200 |
OK |
404 |
Not found |
The response body contains a JSON representation of the requested Car by {id} or is empty when the Car is not found
{
id: 4506364783,
brand: "Larhonda Koch",
licensePlate: "Digna O'Hara",
mileage: 75
}
4. PUT: Update car
Update a car
Request
| Header | Value |
|---|---|
Content-Type |
application/json |
| Property | Value |
|---|---|
URL |
|
Method |
PUT |
-
id: an Integer as the identifier of the car to be updated
The request body contains a JSON representation of the update of the properties of the car WITHOUT the id, since the id is sent as the Path Parameter
PUT http://localhost:8080/api/cars/4
{
brand: "Melanie Medhurst DVM",
licensePlate: "Mr. Burl Raynor",
mileage: 59
}
Response
Our controller’s method returns the updated car respresented as JSON WITH the id
| Header | Value |
|---|---|
Content-Type |
application/json |
| HTTP Status Code | Reason |
|---|---|
200 |
OK |
404 |
Not found |
The response body contains a JSON representation of the updated car
{
id: 10711041518,
brand: "Abe Welch",
licensePlate: "Eilene Wisozk",
mileage: 79
}
5. DELETE: Delete car
Delete a specific car registered in the application by it’s unique identifier
Request
| Property | Value |
|---|---|
URL |
|
Method |
DELETE |
-
id: an Integer as the identifier of the car to be obtained
-
not applicable
DELETE http://localhost:8080/api/cars/3
Response
Our controller’s method returns a statuscode based on the success of the deletion
| HTTP Status Code | Reason |
|---|---|
204 |
No Content |
404 |
Not found |
-
not applicable