mvnw.cmd spring-boot:run), you’ll see this error: I think the code inside the API is simple and don’t need any description.For example if my API wants 10 arguments, then my API function parameters will remain like this :-) I tend to write my APIs this way (using classes for inputs and outputs), because it gives me more flexibility if the number of parameters increase over time. If you checkout the input for this API, I did not use any annotation for parameter mapping, and just used our GetLoveInput class. This API will appear in /love/index path as a GET method. Later we need to inject this service and of course I am not going to discuss Dependency Inject (One of the five rules in SOLID principles). Our controller depends on ILoveService, so we have added it in the constructor.I am not going to discuss attribute routing here, but there’s a good starter point for you. Controller has a for its routing purposes.Controller needs a annotation to declare itself as a controller.So, we go to the Maven website and look spring-boot-starter-web package: link, choose our version which right now is 2.4.0 and then click on it: In order to be able to code for the web we need the spring-boot-starter-web dependency. So far we’ve just added the basic dependencies of Spring Boot: Core and Test. REST API → Add Project Dependencies and Configure them Just install Java Extension Pack or any other extensions to start coding Java.īut it just wrote a “build successful” message and quit! Its because we have not added appropriate dependencies. And I won’t respect CLEAN folder structuring as we are in a hurry! From now on, every java file that I address, is under: src\main\java\com\love\backend\įor the coding part, I wanted to use IntelliJ IDEA for this tutorial, but as I love Microsoft and its products, I’m going to use VSCode. In this article I am not going to dig into testing (maybe another time) and just focus on files under the main folder to write a simple REST API. Under main folder we have our code and under test folder we may write tests.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |