8. Post a Random Vehicle: Exercise
Extend the Autobarn API Client with two new commands:
rwill create one random vehiclelwill loop, creating a random vehicle every 1 second until you press any key, at which point it returns to the main menu.
To create a vehicle, send an HTTP POST to https://autobarn.dev/api/vehicles/
The POST should have the Content-Type application/json and match the following example schema:
{
"registration": "ABCD1234",
"modelCode": "volkswagen-beetle",
"year": 1982,
"color": "yellow"
}
- The vehicle
modelCodeshould be selected at random from the codes retrieved from the API in the previous exercise. - The
yearshould be a random integer between 1960 and 2025 - The
colorshould be one of the CSS named colours:- https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
- The
registrationshould be 8 randomly generated characters in the range A-Z 0-9.
API Responses
- 201 Created
- display a success message including the vehicle details
- 400 Bad Request
- display the error message from the response body
- 409 Conflict
- display the error message from the response body
Hints:
System.Random.Sharedprovides an instance of theSystem.Randomrandom number generator you can use to generate random numbers; use the.Next(10)method to generate a random integer between 0 and 10