Package Exports
- halboy
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (halboy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
halboy.js
A library for all things hypermedia.
- Create hypermedia resources
- Marshal to and from plain JS objects
- Navigate JSON+HAL APIs (coming soon!)
API
Resources
With Halboy you can create resources, and pull information from them.
import { Resource } from 'halboy'
const discountResource =
new Resource()
.addLink('self', '/discounts/1256')
.addProperty('discountPercentage', 10)
const itemResources = [
new Resource()
.addLink('self', '/items/534')
.addProperty('price', 25.48)
]
const resource =
new Resource()
.addLink('self', '/orders/123')
.addLink('creator', '/users/rob')
.addResource('discount', discountResource)
.addResource('items', itemResources)
.addProperty('state', 'dispatching')
resource.getLink('self')
// { href: '/orders/123' }
resource.getHref('self')
// '/orders/123'
resource.getProperty('state')
// 'dispatching'
resource
.getResource('creator')
.getProperty('discountPercentage')
// 10
resource
.getResource('items')[0]
.getProperty('price')
// 25.48Marshalling
You can create HAL resources from plain JS objects, and vice versa.
import { Resource } from 'halboy'
const itemResources = [
new Resource()
.addLink('self', '/items/534')
.addProperty('price', 25.48)
]
const resource =
new Resource()
.addLink('self', '/orders/123')
.addLink('creator', '/users/rob')
.addResource('items', itemResources)
.addProperty('state', 'dispatching')
resource.toObject()
// {
// _links: {
// self: { href: '/orders/123' },
// creator: { href: '/users/rob' }
// },
// _embedded: {
// items: [{
// _links: {
// self: { href: '/items/534' }
// },
// price: 25.48
// }]
// },
// state: 'dispatching'
// }
Resource.fromObject(resource.toObject())
.getHref('self')
// '/orders/123'