Questions tagged [hal-json]

HAL - Hypertext Application Language is a format you can use in your API that gives you a simple way of linking. It has two variants, JSON and XML.

HAL provides a set of conventions for expressing hyperlinks to, and embeddedness of, related resources - the rest of a HAL document is just plain old JSON or XML.

Instead of using linkless JSON/XML, or spending time developing a custom media type, you can just use HAL and focus on defining and documenting the link relations that direct your clients through your API.

HAL is a bit like HTML for machines, in that it is generic and designed to drive many different types of application. The difference is that HTML has features for presenting a graphical hypermedia interface to a ‘human actor’, whereas HAL is intended for presenting a machine hypertext interface to ‘automated actors’.

67 questions
15
votes
2 answers

Can anyone provide a good explanation of CURIEs and how to use them?

I've seen CURIEs described in the HAL specification. At first glance, it looks like a way to provide templating for URIs. However, I also see it prominently mentioned that it can be used to access documentation on a rel. Which one is it? Is it…
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
13
votes
1 answer

Cannot do HAL+JSON Level 3 RESTful API with Spring HATEOAS due to lack of clarity surrounding HAL+JSON media-type

Level 3 RESTful API's feature custom media-types like application/vnd.service.entity.v1+json, for example. In my case I am using HAL to provide links between related resources in my JSON. I'm not clear on the correct format for a custom media-type…
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
13
votes
3 answers

Open application/hal+json response inline in browser instead of downloading it

I would like to open "application/hal+json" response inline in my Chrome browser. The problem is that the Chrome browser doesn't recognize the HAL response and downloads it. Before I always used the JSON view extension for Chrome for checking my…
Wilt
  • 41,477
  • 12
  • 152
  • 203
8
votes
1 answer

How to handle nested resources with JSON HAL?

Imagine a REST endpoint (/employees) serving pages of employees in JSON HAL format. An employee lives in a country, which resides in a continent. For both countries and continents there are also separate endpoints. The returned pages contain the…
Marcel Overdijk
  • 11,041
  • 17
  • 71
  • 110
8
votes
2 answers

Entry point to REST/HATEOAS API?

I have started designing an API and have decided to have a go at making it conform to REST/HATEOAS. What should the entry point for the API be? It seems like a common one is GET / but from what I've read it might make more sense logically to use…
DanielGibbs
  • 9,910
  • 11
  • 76
  • 121
6
votes
2 answers

How to build HAL links with "templated:true" using Spring-hateoas?

I'm trying to figure out how to build HAL links with templated: true. If I use BasicLinkBuilder.linkToCurrentMapping().slash("api/public/blogs/{blog}").withRel("blog"); The { and } chars are still encoded. Any idea how to build template URL links…
jiwhiz
  • 87
  • 1
  • 5
6
votes
2 answers

Design RESTful API using HAL - serialize model relationships

I'm relatively new to REST but I've been doing my homework on how RESTful should be. Now I'm trying to create a RESTful api implementing a JSON+HAL serializer for my models which have relationships with other models. Example models in python: class…
olanod
  • 30,306
  • 7
  • 46
  • 75
5
votes
0 answers

spring-hateoas with `use-hal-as-default-json-media-type=false` still response `application/hal+json` by default

I want to disable HAL format by default. Flow the document, I set this property. spring.hateoas.use-hal-as-default-json-media-type=false Then test it: 1. Request with header Accept: application/json. Header: Content-Type:…
FalconIA
  • 91
  • 1
  • 7
5
votes
1 answer

Spring returns Resource in pure JSON not in HAL Format when including spring data rest

When I use the default controller for my Entities, provided by Spring Data Rest everything works like it should. The output looks like this: { "_links" : { "search" : { "href" : "http://localhost:8080/users/search" } }, …
Yannic Bürgmann
  • 6,301
  • 5
  • 43
  • 77
5
votes
2 answers

Why is the HTTP location header only set for POST requests/201 (Created) responses?

Ignoring 3xx responses for a moment, I wonder why the HTTP location header is only used in conjunction with POST requests/201 (Created) responses. From the RFC 2616 spec: For 201 (Created) responses, the Location is that of the new resource which…
Pipo
  • 5,623
  • 7
  • 36
  • 46
5
votes
1 answer

How to add additional attributes to links using Spring Hateoas and HAL?

I'm using Spring Boot and Spring Hateoas configured with @EnableHypermediaSupport(type = HAL). While this works fine in the basic scenario I'd like the to be able to add additional attributes to the links. For example it's easy to return links…
Johan
  • 37,479
  • 32
  • 149
  • 237
4
votes
2 answers

Using the HAL vocab with JSON-LD

I was wondering, is there a way to use the HAL concepts with JSON-LD? I have the current jsonld document: { "@context": { "hal": "http://stateless.co/hal#", "schema": "http://schema.org", "_links": { "@id":…
inf3rno
  • 24,976
  • 11
  • 115
  • 197
4
votes
1 answer

Save related entities spring data rest HAL-JSON

I have the follow problem I have a basic configuration of spring data rest (Nothing fancy, nothing custom). Using spring-data-rest-webmvc 2.0.0 RELEASE and spring-data-jpa 1.5.0 RELEASE Class A @Entity public class A { @Id …
Charlires
  • 863
  • 1
  • 11
  • 30
3
votes
1 answer

Returning an empty "content" array when the page has no elements

From the AbstractRepositoryRestController#entitiesToResources source: if (page.getContent().isEmpty()) { return pagedResourcesAssembler.toEmptyResource(page, domainType, baseLink); } When a page has no elements, Spring Data REST puts into the…
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
3
votes
2 answers

How to use a @FeignClient to map a HAL JSON _embedded collection

We're trying to use a spring-cloud @FeignClient to call the HAL-JSON REST API of a microservice from another microservice. The service is implemented with Spring Data Rest, Spring Boot 1.4, with Hateoas enabled by default. Using a dedicated DTO on…
1
2 3 4 5