Angular2 HATEOAS support

I have a calm web service with support for HATEOAS links. When I call " http: // localhost: 8080 / v1 / bookings / 1225380? Lock = true " link I got the following resource URLs. I want to integrate these Hypermedia with my Angular2 application (recently upgraded to the final version). I found several resources that were implemented using Angular1 with the support of Angular HAL (links - https://paulcwarren.wordpress.com/2015/04/03/role-based-spas-with-angularjs-and-spring-hateoas/ , https://github.com/LuvDaSun/angular-hal/tree/master/src ). But I can not find the resource for Angular2.

"links": [
  {
    "rel": "client",
    "href": "http://localhost:8080/v1/clients/10000"
  },
  {
    "rel": "passengers",
    "href": "http://localhost:8080/v1/bookings/1225380/passengers"
  },
  {
    "rel": "itinerary",
    "href": "http://localhost:8080/v1/bookings/1225380/itinerary"
  },
  {
    "rel": "self",
    "href": "http://localhost:8080/v1/bookings/1225380?lock=true"
  },
  {
    "rel": "clientBookingHistory",
    "href": "http://localhost:8080/v1/bookings/1225380/clientBookingHistory/10000"
  }
]
+4
source share
1

Injectable angular http. , http .

@Injectable() 
export class Hypermedia {

   constructor(private http: Http) { }

   get(links: any[], rel: String, body?: any, options?: RequestOptionsArgs): Observable<Response> {
    var link = null;
    var request = null;

    // Find the right link
    links.forEach(function (_link) {
        if (_link.rel === rel) {
            link = _link
            return;
        }
    });

    return this.http.get(link.href);
}

}

,

constructor(private hypermedia:Hypermedia)

, , http

this.hypermedia.get(myHypermediaLinksArray,myRel)

, :)

+1

Source: https://habr.com/ru/post/1655798/


All Articles