If tiny, friendly aliens came to Earth, they would definitely fall in love with dogs. The only problem would be that they wouldn't have them on their home planet. They would surely ask Codecool to help them automatize, by creating Robo-Dogs and populate their planet with four-legged friends. Let's prepare for this case, and bring world peace to the universe! 🐾
- creating a new Spring project
- working with HTTP requests
- routing with Spring
- respond differently based on the HTTP request's method value
- organize your project into layers
- check your work using Postman
-
After you clone the repository of the project it only has a README.md file in it. Set up the project for RoboDogApplication.
- Spring project has been created with a Spring Web dependency in
pom.xmlfile. - There is a class with
SpringBootApplicationannotation, containing themainmethod
- Spring project has been created with a Spring Web dependency in
-
The application can model a Dog by their age, name and breed. This class should be located in the
modellayer.- The application has a model class for Dog with properties of age, name, breed.
- The model class is located in a
modellayer. - The
Breedproperty has its own type (doesn't use strings).
-
There is a
DogCreatorclass in theservicelayer, which contains acreateRandomDog()method.createRandomDog()returns a new instance of theDogclass with randomized values of the following properties: name, age, breed.
-
Who let the dogs out? Let's shelter them! Create a
DogStorageclass for handling the dogs.- Dogs are stored in an ordered collection.
- A dog can be added to the collection.
- A randomly generated dog can be added to the collection
- The collection of all dogs can be returned.
- The first dog with given name can have its age and breed properties updated.
-
Create a
DogControllerclass in the acontrollerlayer to let others interact with the dogs. containing methods for get all dogs, create a random dog, add a specific dog, or update the first dog of a given name. To achieve this behaviour, this class should not contain the full logic in itself. It should be rather wired with another class responsible for services like this.- Class has the
RestControllerbehaviour. - Class is wired with
DogStorage - Controller has a GET endpoint for returning all the stored dogs.
- Controller has a GET endpoint for returning a randomly created dog.
- Controller has a POST endpoint for adding a new dog (dog's data is kept in the Request Body)
- Controller has a PUT endpoint for updating the first dog with given name, which is provided in the path variable (age and breed properties can be updated via Request Body)
- Class has the
-
Use Postman to check your endpoints! Create a new collection for this project, and create requests for testing all your endpoints. Use JSON format for testing POST requests.
- A collection of all dogs is returned after sending a GET request.
- A randomly created dog is returned after sending a GET request.
- A new dog is added to the collection after sending a POST request, with providing the dog's model in JSON format in the Request Body.
- The first dog with given name, provided in the path variable, is modified by the values provided in the Request Body, after sending a PUT request.
None
- you can use Spring initializr tool to generate your Spring project
- you can handle variables in the request URL by using @PathVariable annotation
- you can use the information coming from a POST request to use it as an object described by one of your model classes using @RequestBody annotation