标签: hal-json

使用HAL词汇与JSON-LD

我想知道,有没有办法在JSON-LD中使用HAL概念?

我有当前的jsonld文档:

{
    "@context": {
        "hal": "http://stateless.co/hal#",
        "schema": "http://schema.org",
        "_links": {
            "@id": "hal:link",
            "@container": "@index"
        }
    },
    "@type": ["schema:Person", "hal:Resource"],
    "name": "Jon Snow",
    "_links": {
        "self": {
            "href": "/users/123"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何定义该href具有@type@id,等等...

有没有办法基于RDF(S)定义HAL词汇并以某种方式将其导入我的jsonld文档的@context中,或者我应该做其他什么?
(我试图描述具有各种属性的超链接,如链接关系,HTTP方法,接受的媒体类型,语言,IRI模板,输入字段等等......所以@id类型不足以让我描述链接.)

rest rdf hateoas hal-json json-ld

4
推荐指数
1
解决办法
1259
查看次数

嵌入式HAL资源集合中没有自我href

我使用self href客户端的from my HAL资源来查找CRUD操作的正确路径.在单个(吨)资源中,这工作正常(请参阅下面的地址资源,_links包含self href嵌入资源中包含的地址资源)但是当归结为集合时,这是一个不同的故事.该_links集合时是一家集都没有呈现_embedded.

之前我通过阅读第一个孩子的网址来解决这个问题.但这还不够.如果集合是空的,我只有一个空数组,不可能像这样提取url.如果我想在集合中创建一个新项目,我希望我的客户端POST通过阅读self href来自知道在哪里发送数据_links._links像这样包含我的收藏是一个好主意:

{
    "_links": {
        "self": {
            "href": "http://example.com/api/v1/users/1"
        }
    },
    "_embedded": {
        "contacts": {
Run Code Online (Sandbox Code Playgroud)

现在我可以在这里访问self href:

            "_links": {
                "self": {
                    "href": "http://example.com/api/v1/users/1/contacts"
                }
            },
            "_embedded": {
                "contacts": [
                    {
                        "_links": {
                            "self": {
                                "href": "http://example.com/api/v1/users/1/contacts/2"
                            }
                        },
                        "id": "2",
                        "name": "John Smith"
                    },
                    {
                        "_links": {
                            "self": {
                                "href": "http://example.org/api/v1/users/1/contacts/3"
                            }
                        },
                        "id": "3",
                        "name": "Jane …
Run Code Online (Sandbox Code Playgroud)

collections self href embedded-resource hal-json

3
推荐指数
1
解决办法
2148
查看次数

使用Traverson的Spring-Hateoas客户

我想使用Traverson的Spring-Hateoas提供的休息服务,但是遇到以下问题,我在网络上找不到任何东西。我正在使用Spring-Boot 1.1.10.RELEASE

我的客户呼叫如下所示:

... 

final Traverson traverson = new Traverson(new URI("http://localhost:8080/bbsng-app-rest"), MediaTypes.HAL_JSON);

...
Run Code Online (Sandbox Code Playgroud)

我得到以下问题:

java.lang.NoClassDefFoundError: Could not initialize class org.springframework.hateoas.client.Traverson
at at.compax.bbsng.client.mvc.client.service.BerufServiceImpl.findeAlleBerufe(BerufServiceImpl.java:41)
at at.compax.bbsng.client.mvc.rest.controller.BerufController$1.call(BerufController.java:25)
at at.compax.bbsng.client.mvc.rest.controller.BerufController$1.call(BerufController.java:1)
at org.springframework.web.context.request.async.WebAsyncManager$4.run(WebAsyncManager.java:316)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:745)
Run Code Online (Sandbox Code Playgroud)

=====

相关配置:

POM:

...

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.plugin</groupId>
        <artifactId>spring-plugin-core</artifactId>
        <version>1.1.0.RELEASE</version>
    </dependency>

...
Run Code Online (Sandbox Code Playgroud)

应用类别:

@Configuration
@EnableHypermediaSupport(type = HAL)
@EnableAutoConfiguration
public class ApplicationClientMvc {

    public static void main(final String[] args) {
        SpringApplication.run(ApplicationClientMvc.class, …
Run Code Online (Sandbox Code Playgroud)

client resttemplate spring-hateoas hal-json

3
推荐指数
1
解决办法
2213
查看次数

Angular - 将 HAL 转换为 JSON

以下服务从 REST 服务中提取类别对象,并以 HAL 格式返回它们。现在我尝试将该响应转换为 JSON。为此,我搜索并尝试了不同的解决方案,例如chariotsolutions等。有些是基于“@angular/http”的响应,该响应已被弃用并且我无法工作。

我该如何进行转换?

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

import { Observable } from 'rxjs/Rx';
import { of } from 'rxjs/observable/of';
import 'rxjs/Rx';
import 'rxjs/add/operator/map';

import { Category } from './category';

@Injectable()
export class CategoryService {

  private categoriesUrl = 'http://localhost:8080/account/categories';

  constructor(private http: HttpClient) { }

  getCategories(): Observable<Category[]> {
    return this.http.get<Category[]>(this.categoriesUrl);
  }

}
Run Code Online (Sandbox Code Playgroud)

HAL 响应

{
  "_embedded": {
    "categories": [
      {
        "id": 1,
        "name": "hardware",
        "description": "comprises …
Run Code Online (Sandbox Code Playgroud)

json hal-json angular

2
推荐指数
1
解决办法
3176
查看次数