hal_specification | HAL Specification
kandi X-RAY | hal_specification Summary
kandi X-RAY | hal_specification Summary
HAL Specification
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of hal_specification
hal_specification Key Features
hal_specification Examples and Code Snippets
Community Discussions
Trending Discussions on hal_specification
QUESTION
Before this is marked as a duplicate, it is not, at least not of any of the first 10+ search results. This situation adds a level of complexity that I can't quite figure out.
tl;dr What works for exclusively specifying exactly one property of n must exist, or that a property must exist in exactly one of n spots, does not work when used on a nested property. TS Playground
I'm doing some Saturday overengineering--like ya do. My project uses JSON HAL documents (HAL documents basically describe an entity of some sort and with a _links
property, define the available behavior), however, the backend (which I did not write) does not always send the documents in the same shape. I have a normalizeRepresentation()
function that takes in what the server sends me and morphs it into what it should look like.
To produce minimal code, I've removed stuff regarding _links
.
Differences between standard HAL:
- the entity data is on exactly one of:
- the root document itself
- the
document
property - the
data
property - the
item
property - the
item.data
property
- there is an optional
contentType
property that is either placed on the root document or inside the entity data, but not both
normalizeRepresentation()
initially had the signature:
ANSWER
Answered 2021-Apr-04 at 01:16I think I've done it, by basically expanding all of the helper types out into one big union. This helped me see what was supposed to be happening, and also made it work better in the end. I found it important to add x?: never
in many places, so that TS can properly prevent you from mixing together different variants of the data structure.
The errors don't always occur on the same lines as your original code, but I'm not sure much can be done about that.
I think this also still has some limitations, for example, it probably won't work if T
legitimately has a data
or contentType
key.
At some level of complexity, though, I would question the value of having these very strict TS types, which work best with object literals (where the compiler actually gives an error if you add unknown keys), when you said the data is coming from a server anyway, which implies that mostly only your test code will ever be working with object literals. If you're able to leverage these types on the server where the objects are being generated, though, that could be beneficial.
QUESTION
I want many to many relation mapping with explicit join table.
My java spring project is providing REST api in HAL format and now it has only two types of classed:
- entities defined and
- "empty" interfaces for repositories (annotated by @RepositoryRestResource).
Sidenote, dependencies are circa these:
...ANSWER
Answered 2019-Nov-05 at 13:19To make many2many association work nicely with spring data rest things and provide HAL representation with correct things, you have first know a bit of JPA/Hibernate. There are two approaches (1 and 2 from question, as third is only shortcut for second one and working in Hibernate only.).
Both approaches are shown in proof of concept repository in tags branch. I use given repository to test various set-ups of project.
Approach 1, EmbeddedId. It does use hackish thing in FixConfig class in BackendIdConverter bean, where it uses bookRepository to get Book entity when it parses request id from url onto embedable id class.
Approach 2, IdClass. It is using plain Integers int its IdClass and does seem to be correct solution.
I think that first approach can be modified to work similarly as second, but I am not able to do it for now.
I would mark as solution any answer providing some insight for "why" it is like this.
QUESTION
I'm writing Web API in ASP NET Core and I want to consume it from single page applications (e.g. using Angular, Vue, React), native desktop applications and mobile applications.
I stumbled across concept called "HATEOAS" and I learnt that the API I'm building isn't really RESTful and I wrongly named it RESTful (https://devblast.com/b/calling-your-web-api-restful-youre-doing-it-wrong).
And it seems like most of the people use this term badly (Roy T. Fielding - man behind REST idea about his annoyance: http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven)
From what I learnt the idea behind HATEOAS is thinking of your application as you think of websites, that means it exposes links to resources (like in HTML) so you don't have to hardcode the links/endpoints in your client code and your client code won't break if you change some endpoint (?).
Another thing is that it makes your API discoverable without any documentation, i.e. API describes itself (like meta API)
When I look at the existing "REST" clients for C# for example:
They have "REST" in their name but none of them dig into the concept of HATEOAS. So why the heck are they named "Rest clients"?
How HATEOAS is supposed to be used on the client-side? To my surprise there isn't much about it on the internet, there's a lot about how to implement HATEOAS on the server, but there isn't much how it's supposed to work on the client. That most often should provide navigation logic.
Besides of that all, there are many API client generators (parsing OpenAPI specification) like AutoRest (nothing about hyperlinks and HATEOAS, to my surprise), or NSwag
I was googling for few hours to learn about HATEOAS, but most often people talk about it without describing how to use it (there are almost none client libraries supporting it).
There are many standards for it like HAL, Ion etc. But there are almost none rest client libraries implementing those standards. There's also json:api. All these standards are very similar.
So my question is:
Is HATEOAS applicable for applications like SPAs, mobile and desktop clients?
What's the real use case for HATEOAS, if I can as well hardcode my endpoints, or generate new API client from OpenAPI (Swagger) specification as it changes?
Is it even worth to bother with it?
There are almost none practical examples of interacting with HATEOAS or Hypermedia APIs, or am I missing something here and they're not supposed to be used by my client code?
To me it seems like implementing it on both client and the server is a lot of boilerplate code, so why aren't there many libraries supporting it out of the box (using one of the standard). It seems like json:api has many implementations http://jsonapi.org/implementations/#client-libraries-net
...ANSWER
Answered 2018-Apr-19 at 14:11REST is a paradigm that applies more broadly than just the HTTP protocol and so-called "web APIs". A RESTful Web API, is one that simply applies principles from the REST paradigm to client-server communication over HTTP. As such, it doesn't necessary follow everything in REST and doesn't necessarily need to.
While HATEOAS is a nice concept, there's no HTTP client that actually implements it out of the box (at least that I'm aware of). You can feel free to make your API implement it, but that doesn't mean it will actually be used, and while your API may be "RESTful", it doesn't mean every client will be. Part of the foundation of the HTTP protocol is adaptive communication. In other words, a client need not support all the features of a server and vice versa. The client and server, instead, work with what they share in common in terms of functionality.
QUESTION
I have the following HAL+JSON sample:
...ANSWER
Answered 2019-Jan-14 at 14:08The company
object will be under Embedded _embedded
object.
like
QUESTION
The HAL spec that I am working with says that you can have multiple links of the same type on a resource like this:
...ANSWER
Answered 2019-Jan-06 at 03:51If you call ResourceSupport::add()
twice (or more) with the same withRel value, it creates an array ref with that name containing each of the items.
QUESTION
I'm consuming a third party WebApi using ServiceStack. Imagine this API has the following route.
https://api.example.com/v1/people/{id}
returns the person with the specified ID.
JSON:
...ANSWER
Answered 2018-Feb-20 at 08:03The purpose of DTOs (Data Transfer Objects) is to define the Service Contract with a Typed Schema that matches the shape of the Wire Format so they can be used with a generic serializer to automatically Serialize/Deserialize payloads without manual custom logic boilerplate.
So I'm not following why you're trying to hide the public schema of the DTO and why the Types contain embedded logic, both of which are anti-patterns for DTOs which should be benign impl-free data structures.
My first recommendation is to change your Types so they are DTOs where their public schema matches the shape of the data it's trying to deserialize into.
Failing that, given your Types aren't DTOs and you want to use it to hydrate a data model I'd look at creating a separate Typed DTO and use an AutoMapping library (or a custom Type mapper extension method) to copy the data from the Typed DTO into your ideal Data Model.
If you don't want to maintain a separate Typed Data DTO from your Data Model you can use a generic JSON parser which will deserialize arbitrary data structures into a loose-typed generic .NET Data Structures like Dictionary
.
If you're just looking to avoid public properties and are happy to have public fields instead you can specify ServiceStack.Text's serializer to populate public fields with:
QUESTION
According to this specification, applications exposing data in hal+json format should provide embedded links in the _links json field. However, if I declare my REST Repository in spring-data 1.5.9 like this:
...ANSWER
Answered 2018-Jan-22 at 04:37I don't believe Spring HATEOAS does HAL out of the box. You can enabled it by adding the following to your configuration:
QUESTION
ANSWER
Answered 2017-Jun-23 at 07:55As observable in the specs you posted, you can have links and/or embedded resources:
A resource's links should sit as a property of that resource:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install hal_specification
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page