Thursday 12 December 2019

Changing the base uri for spring data REST application


This is continuation to my previous post.

By default, Spring Data REST serves REST resources at the root URI, '/'.

For example,
http://localhost:8080/
http://localhost:8080/employees

You can change this property by adding below property to application.properties.
spring.data.rest.basePath=/api

Rerun the application after adding this property, you can access the application at below end points.
http://localhost:8080/api

Create an employee
Method: POST
Body:
{
         "firstName" : "Bhadri",
         "lastName" : "Narayana"
}

You will receive below response.
{
  "firstName": "Bhadri",
  "lastName": "Narayana",
  "_links": {
    "self": {
      "href": "http://localhost:8080/api/employees/1"
    },
    "employee": {
      "href": "http://localhost:8080/api/employees/1"
    }
  }
}

You can download complete working application from this link.



Previous                                                    Next                                                    Home

No comments:

Post a Comment