spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
913 stars 559 forks source link

Some documentation showing how to exposing a resource with "title name/index" [DATAREST-800] #1118

Open spring-projects-issues opened 8 years ago

spring-projects-issues commented 8 years ago

Christian Bongiorno opened DATAREST-800 and commented

I am using spring-data-rest + hal browser by importing the dependency.

It seems to work well enough but there doesn't seem to ba a way to provide details to:

"title | name/index | docs"

In the links section of the browser. I assume these can be discovered resources but quite a bit of sniffing around isn't finding it

Having spent more time on this I am flagging it as a bug because the the controller used to provide the HAL link data doesn't even produce what is needed:

GET /hal HTTP/1.1
Host: localhost:9090
Connection: keep-alive
Cache-Control: max-age=0
Accept: application/hal+json, application/json, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36
Referer: http://localhost:9090/hal/browser/index.html
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8

Date: Thu, 14 Apr 2016 20:11:53 GMT

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Application-Context: application
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 14 Apr 2016 20:11:53 GMT

596
{
  "_links" : {
    "schedules" : {
      "href" : "http://localhost:9090/hal/schedules{?page,size,sort}",
      "templated" : true
    },
    "certifications" : {
      "href" : "http://localhost:9090/hal/certifications{?page,size,sort}",
      "templated" : true
    },
    "organizations" : {
      "href" : "http://localhost:9090/hal/organizations{?page,size,sort}",
      "templated" : true
    }
  }
}

I am looking at RepositoryController.listRepositories() and following through this code and there is no property at all being exposed for "title" or "name" or "docs". I imagine "Docs" could be exposed as a org.springframework.data.rest.core.annotation.Description on the repository.

See: org.springframework.hateoas.ResourceSupport

Maybe it's not a bug? Maybe it's a feature request. I see your name on the code so I will let you decide


Affects: 2.4.2 (Gosling SR2)

Attachments:

Issue Links:

spring-projects-issues commented 8 years ago

Oliver Drotbohm commented

I'll have that added to the docs. In the mean time, here are the tricks:

  1. Register a CurieProvider like shown here. CurieProvider is documented in detail here.
  2. For the titles use a resource bundle named rest-messages.properties using keys like shown here
spring-projects-issues commented 8 years ago

Christian Bongiorno commented

Ah, you changed this as I was updating it. :)

spring-projects-issues commented 8 years ago

Oliver Drotbohm commented

There's no explicit handling of those properties as the Resource infrastructure, Link etc. is currently media type agnostic and thus doesn't know anything about any HAL-specific properties. The addition of the title is purely done on rendering time (in the HAL specific Jackson module), translating the link relation into a human readable text by using a resource bundle with a predefined key structure. See this commit for details

spring-projects-issues commented 8 years ago

Christian Bongiorno commented

Ok, fair enough. I see what's going on. But, this approach isn't really keeping inline with having the documentation hooked into the code. There are now 3 seperate things to manage:

1) Repository 2) Documentation for said repo 3) Properties file for getting the title and name (that just happens to have properties that line up with the repo name).

On the Repository interface annotation there is already: @RepositoryRestResource(collectionResourceRel = "drivers", path = "drivers",itemResourceDescription = @Description("Foo") )

path and resourceRel are both exposed on the UI as part of the resource but description is not. Exposing @Description as documentation seems ideal. Is there are reason to not do this?

Based on your previous links I can do this myself with some work.

spring-projects-issues commented 8 years ago

Christian Bongiorno commented

Any plans to make this more seemless?

I implemented less-than-ideal means of discovering these details