From the course: Java for All Platforms: Desktop, Web, and Mobile Development

Unlock the full course today

Join today to access over 23,500 courses taught by industry experts.

Building APIs

Building APIs

- [Instructor] Now, we're going to build a simple API using the Spring Framework. The first thing that we need to do is call out this class as a REST controller, which will enable us to be able to hit endpoints and return data from the server. Under the @SpringBootApplication annotation, type @RestController, then we're going to create a method that will return a value, and this is the great thing about Spring. We can create an API with just a few lines of code. The first thing we needed to define in the API is the endpoint. So we're going to go to the root of the server, slash, something. So to define our endpoint, we use this annotation called GetMapping. So type @GetMapping and then in parentheses, the endpoint name, which will be /hello in this case. Just like that, and then we define a public method that returns some kind of data. So public, String, hello and in the parenthesis, what we're going to do is take a value…

Contents