question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

self-href urls are not proper in rest api

See original GitHub issue

I was trying to run spring-petclinic-rest in my local. I was able to run and build properly. But when I hit the URL http://localhost:9966/petclinic/ This shows me below response

{ "_links" : { "petTypes" : { "href" : "http://localhost:9966/petclinic/petTypes" }, "vets" : { "href" : "http://localhost:9966/petclinic/vets" }, "users" : { "href" : "http://localhost:9966/petclinic/users" }, "visits" : { "href" : "http://localhost:9966/petclinic/visits" }, "pets" : { "href" : "http://localhost:9966/petclinic/pets" }, "specialties" : { "href" : "http://localhost:9966/petclinic/specialties" }, "owners" : { "href" : "http://localhost:9966/petclinic/owners" }, "profile" : { "href" : "http://localhost:9966/petclinic/profile" } } }

Upon clicking vets link from above, I got below response -

{ "firstName" : "Helena", "lastName" : "Leary", "_links" : { "self" : { "href" : "http://localhost:9966/petclinic/vets/1" }, "vet" : { "href" : "http://localhost:9966/petclinic/vets/1" }, "specialties" : { "href" : "http://localhost:9966/petclinic/vets/1/specialties" } } }

But when I click on the self href url- it end up in being GET method not supported exception.

Actual URL for getting vets by id is http://localhost:9966/petclinic/api/vets/1

In code I could not find where it is configured or from where these links are coming. Can someone suggest how to add api in self href urls.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
areycommented, Jul 5, 2018

Spring Data Rest exports Spring Data repositories as REST resources with HAL. It may not uses the @RestController. Thus we have 2 API in a single war. If you set spring.data.rest.basePath=/datarest, at startup, you will see 2 endpoints for retrieving a pet by its ID:

  • /api/pets/{petId}],methods=[GET]
  • {[/datarest/{repository}/{id}],methods=[GET]

For my point of view, the Spring Petclinic Rest application could have a branch or a fork with Spring Data Rest. And the swagger-ui.html should be the hompepage of the master branch.

0reactions
kuldeepsidhu88commented, Jul 5, 2018

Yes. Agree. swagger-ui.html should be homepage. As of now it shows REST resources info on homepage at http://localhost:9966/petclinic/ People can get confused seeing the REST URLs and try to retrieve resources using those.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why add links to the response of a REST API? - Stack Overflow
There are multiple opinions about this. So in my answer I'm putting on the hat of someone who does want to add these...
Read more >
REST with Hypermedia - Hot or Not? - Reflectoring
A discussion of what Hypermedia with REST means and a guide to decide whether hypermedia is a match for your use case.
Read more >
API design: Why you should use links, not keys, to represent ...
HTTP has a special method for this purpose: PUT. PUT means "create the resource at this URL if it does not already exist,...
Read more >
REST lesson learned: Consider a self link on all resources
Notice the link with the rel value of "self"; from its href value you now know that the canonical URL of that product...
Read more >
Self vs. related links (and what to return) - JSON API
Anyway, am I correct to assume that if a client both the self and related link (of the author relationship) return the same...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found