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.

Endpoints
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

Purpose

Obtains a list of cars

Request

HTTP Request Header Parameters
Header Value

Content-Type

application/json

Request properties
Property Value

URL

http://localhost:8080/api/cars

Method

GET

Path parameters
  • not applicable

Request Body
  • not applicable

Sample request
GET http://localhost:8080/api/cars

Response

Our controller’s method returns a list of cars represented as JSON

HTTP Response Header Parameters
Header Value

Content-Type

application/json

Response messages
HTTP Status Code Reason

200

OK

Response body

The response body contains a JSON representation of the list of cars or an empty list ([])

Sample response
[{
	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

Purpose

Create a car

Request

HTTP Request Header Parameters
Header Value

Content-Type

application/json

Request properties
Property Value

URL

http://localhost:8080/api/cars

Method

POST

Path parameters
  • not applicable

Request Body

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

Sample request
POST http://localhost:8080/api/cars
Sample request body
{
	brand: "Nova Purdy",
	licensePlate: "Ross Kling",
	mileage: 71
}

Response

The response body contains a JSON representation of the created car

HTTP Response Header Parameters
Header Value

Content-Type

application/json

Response messages
HTTP Status Code Reason

200

OK

Response body

Our controller’s method returns the created car respresented as JSON WITH the id, since the id is NOW set by the application

Sample response body
{
	id: 14249049172,
	brand: "Aldo Doyle",
	licensePlate: "Helaine Ritchie",
	mileage: 88
}

3. GET: Get car

Purpose

Obtains a specific car registered in the application by it’s unique identifier

Request

HTTP Request Header Parameters
Header Value

Content-Type

application/json

Request properties
Property Value

URL

http://localhost:8080/api/cars/{id}

Method

GET

Path parameters
  • id: an Integer as the identifier of the car to be obtained

Request Body
  • not applicable

Sample request
GET http://localhost:8080/api/cars/3

Response

Our controller’s method returns a car represented as JSON

HTTP Response Header Parameters
Header Value

Content-Type

application/json

Response messages
HTTP Status Code Reason

200

OK

404

Not found

Response body

The response body contains a JSON representation of the requested Car by {id} or is empty when the Car is not found

Sample response body
{
	id: 4506364783,
	brand: "Larhonda Koch",
	licensePlate: "Digna O'Hara",
	mileage: 75
}

4. PUT: Update car

Purpose

Update a car

Request

HTTP Request Header Parameters
Header Value

Content-Type

application/json

Request properties
Property Value

URL

http://localhost:8080/api/cars/{id}

Method

PUT

Path parameters
  • id: an Integer as the identifier of the car to be updated

Request Body

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

Sample request
PUT http://localhost:8080/api/cars/4
Sample request body
{
	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

HTTP Response Header Parameters
Header Value

Content-Type

application/json

Response messages
HTTP Status Code Reason

200

OK

404

Not found

Response body

The response body contains a JSON representation of the updated car

Sample response body
{
	id: 10711041518,
	brand: "Abe Welch",
	licensePlate: "Eilene Wisozk",
	mileage: 79
}

5. DELETE: Delete car

Purpose

Delete a specific car registered in the application by it’s unique identifier

Request

Request properties
Property Value

URL

http://localhost:8080/api/cars/{id}

Method

DELETE

Path parameters
  • id: an Integer as the identifier of the car to be obtained

Request Body
  • not applicable

Sample request
DELETE http://localhost:8080/api/cars/3

Response

Our controller’s method returns a statuscode based on the success of the deletion

Response messages
HTTP Status Code Reason

204

No Content

404

Not found

Response body
  • not applicable