Skip to content

Restful Web Services with Spring Boot Part I

Amitha R edited this page Dec 17, 2020 · 8 revisions

Restful Web Services with Spring Boot

RESTful Web Services

Step 1 - Initializing a RESTful Services Project with Spring Boot

  • start.spring.io
  • Provide details:
    • Maven Project, Java, SpringBoot - 2.0.0(SNAPSHOT)
    • Group : com.example.project
    • Artifact : restful-web-services
    • dependencies : Web , DevTools, JPA, H2
  • Generate Project

  • For any Maven project need to specify a group id and artifact id.

  • Spring Initializer creates a Maven Project, puts it in a Zip and downloaded to the downloads folder.

  • In eclipse -> Import -> Existing Maven Project

  • Load the maven project.
  • Maven would download all the dependencies listed in the pom.xml file.

Step 2: Understanding the RESTful services created

  • REST is a style of software architecture for distributed hypermedia systems (design resources and how you expose them using HTTP).
  • REST makes best use of HTTP.
  • Key abstraction is a resource - each resource has a URI. ** (Users (1) - Posts(Many))
  • Different RESTful Web services we would create.
  1. Retrieve all Users - GET /users
  2. Create a User - POST /users
  3. Retrieve one User - GET /users/{id} -> /users/1
  4. Delete a User - DELETE /users/{id} -> /users/1
  5. Retrieve all posts for a User - GET /users/{id}/posts
  6. Create posts for a User - POST /users/{id}/posts
  7. Retrieve details of a post - GET /users/{id}/posts/{post_id}

Step 3 - Create a HelloWorldBean request

  • Class object that in turn returns a String.
  • Getter, Setter and toString Method.
  • Without a Getter - encounter an error - No converter found for return value of type.

Clone this wiki locally