• Stars
    star
    1,253
  • Rank 37,509 (Top 0.8 %)
  • Language
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Structured Interface for Representing Entities, super-rad hypermedia

Siren: a hypermedia specification for representing entities

DOI

Your input is appreciated. Feel free to file a GitHub Issue, a Pull Request, or contact us. Thank you!

Example

Below is a JSON Siren example of an order, including sub-entities. The first sub-entity, a collection of items associated with the order, is an embedded link. Clients may choose to automatically resolve linked sub-entities. The second sub-entity is an embedded representation of customer information associated with the order. The example also includes an action to add items to the order and a set of links to navigate through a list of orders.

The media type for JSON Siren is application/vnd.siren+json.

{
  "class": [ "order" ],
  "properties": { 
      "orderNumber": 42, 
      "itemCount": 3,
      "status": "pending"
  },
  "entities": [
    { 
      "class": [ "items", "collection" ], 
      "rel": [ "http://x.io/rels/order-items" ], 
      "href": "http://api.x.io/orders/42/items"
    },
    {
      "class": [ "info", "customer" ],
      "rel": [ "http://x.io/rels/customer" ], 
      "properties": { 
        "customerId": "pj123",
        "name": "Peter Joseph"
      },
      "links": [
        { "rel": [ "self" ], "href": "http://api.x.io/customers/pj123" }
      ]
    }
  ],
  "actions": [
    {
      "name": "add-item",
      "title": "Add Item",
      "method": "POST",
      "href": "http://api.x.io/orders/42/items",
      "type": "application/x-www-form-urlencoded",
      "fields": [
        { "name": "orderNumber", "type": "hidden", "value": "42" },
        { "name": "productCode", "type": "text" },
        { "name": "quantity", "type": "number" }
      ]
    }
  ],
  "links": [
    { "rel": [ "self" ], "href": "http://api.x.io/orders/42" },
    { "rel": [ "previous" ], "href": "http://api.x.io/orders/41" },
    { "rel": [ "next" ], "href": "http://api.x.io/orders/43" }
  ]
}

Introduction

Siren is a hypermedia specification for representing entities. As HTML is used for visually representing documents on a Web site, Siren is a specification for presenting entities via a Web API. Siren offers structures to communicate information about entities, actions for executing state transitions, and links for client navigation.

Siren is intended to be a general specification of a generic media type that can be applied to other types that are not inherently hypermedia-powered. The initial implementation is JSON Siren. Other implementations, such as XML Siren, may also be implemented using the Siren specification.

All examples in this document are in the JSON Siren format.

Entities

An Entity is a URI-addressable resource that has properties and actions associated with it. It may contain sub-entities and navigational links.

Root entities and sub-entities that are embedded representations SHOULD contain a links collection with at least one item contain a rel value of self and an href attribute with a value of the entity's URI.

Sub-entities that are embedded links MUST contain an href attribute with a value of its URI.

Entity

class

Describes the nature of an entity's content based on the current representation. Possible values are implementation-dependent and should be documented. MUST be an array of strings. Optional.

properties

A set of key-value pairs that describe the state of an entity. In JSON Siren, this is an object such as { "name": "Kevin", "age": 30 }. Optional.

entities

A collection of related sub-entities. If a sub-entity contains an href value, it should be treated as an embedded link. Clients may choose to optimistically load embedded links. If no href value exists, the sub-entity is an embedded entity representation that contains all the characteristics of a typical entity. One difference is that a sub-entity MUST contain a rel attribute to describe its relationship to the parent entity.

In JSON Siren, this is represented as an array. Optional.

links

A collection of items that describe navigational links, distinct from entity relationships. Link items should contain a rel attribute to describe the relationship and an href attribute to point to the target URI. Entities should include a link rel to self. In JSON Siren, this is represented as "links": [{ "rel": ["self"], "href": "http://api.x.io/orders/1234" }] Optional.

actions

A collection of action objects, represented in JSON Siren as an array such as { "actions": [{ ... }] }. See Actions. Optional

title

Descriptive text about the entity. Optional.

Sub-Entities

Sub-entities can be expressed as either an embedded link or an embedded representation. In JSON Siren, sub-entities are represented by an entities array, such as { "entities": [{ ... }] }.

Embedded Link

A sub-entity that's an embedded link may contain the following:

class

Describes the nature of an entity's content based on the current representation. Possible values are implementation-dependent and should be documented. MUST be an array of strings. Optional.

rel

Defines the relationship of the sub-entity to its parent, per Web Linking (RFC5988) and Link Relations. MUST be a non-empty array of strings. Required.

href

The URI of the linked sub-entity. Required.

type

Defines media type of the linked sub-entity, per Web Linking (RFC5988). Optional.

title

Descriptive text about the entity. Optional.

Embedded Representation

Embedded sub-entity representations retain all the characteristics of a standard entity, but MUST also contain a rel attribute describing the relationship of the sub-entity to its parent.

Classes vs. Relationships

It's important to note the distinction between link relations and classes. Link relations define a relationship between two resources. Classes define a classification of the nature of the element, be it an entity or an action, in its current representation.

Sub-Entities vs Links

Another distinction is the difference between sub-entities and links. Sub-entities exist to communicate a relationship between entities, in context. Links are primarily navigational and communicate ways clients can navigate outside the entity graph.

Links

Links represent navigational transitions. In JSON Siren, links are represented as an array inside the entity, such as { "links": [{ "rel": [ "self" ], "href": "http://api.x.io/orders/42"}] }

Links may contain the following attributes:

rel

Defines the relationship of the link to its entity, per Web Linking (RFC5988) and Link Relations. MUST be an array of strings. Required.

class

Describes aspects of the link based on the current representation. Possible values are implementation-dependent and should be documented. MUST be an array of strings. Optional.

href

The URI of the linked resource. Required.

title

Text describing the nature of a link. Optional.

type

Defines media type of the linked resource, per Web Linking (RFC5988). Optional.

Actions

Actions show available behaviors an entity exposes.

name

A string that identifies the action to be performed. Action names MUST be unique within the set of actions for an entity. The behaviour of clients when parsing a Siren document that violates this constraint is undefined. Required.

class

Describes the nature of an action based on the current representation. Possible values are implementation-dependent and should be documented. MUST be an array of strings. Optional.

method

An enumerated attribute mapping to a protocol method. For HTTP, these values may be GET, PUT, POST, DELETE, or PATCH. As new methods are introduced, this list can be extended. If this attribute is omitted, GET should be assumed. Optional.

href

The URI of the action. Required.

title

Descriptive text about the action. Optional.

type

The encoding type for the request. When omitted and the fields attribute exists, the default value is application/x-www-form-urlencoded. Optional.

fields

A collection of fields, expressed as an array of objects in JSON Siren such as { "fields" : [{ ... }] }. See Fields. Optional.

Fields

Fields represent controls inside of actions. They may contain these attributes:

name

A name describing the control. Field names MUST be unique within the set of fields for an action. The behaviour of clients when parsing a Siren document that violates this constraint is undefined. Required.

class

Describes aspects of the field based on the current representation. Possible values are implementation-dependent and should be documented. MUST be an array of strings. Optional.

type

The input type of the field. This may include any of the following input types specified in HTML5:

hidden, text, search, tel, url, email, password, datetime, date, month, week, time, datetime-local, number, range, color, checkbox, radio, file

When missing, the default value is text. Serialization of these fields will depend on the value of the action's type attribute. See type under Actions, above. Optional.

value

A value assigned to the field. Optional.

title

Textual annotation of a field. Clients may use this as a label. Optional.

Usage Considerations

Siren supports a resource design style that doesn't have to be primarily CRUD-based. A root entity may take ownership of facilitating changes to sub-entities via actions. Using Siren allows you to easily provide a task-based interface through your Web API.

Feedback

Siren is still a work in progress looking for some real world usage and feedback. Please contribute! Feel free to use GitHub Issues to make suggestions or fire up a Pull Request with changes to be reviewed. Thank you!

More Repositories

1

postman2openapi

Convert a Postman collection to an OpenAPI definition.
Rust
312
star
2

postmanctl

A command-line Interface to the Postman API.
Go
52
star
3

pipeworks

Create pipes. Fit 'em together. Start the flow!
JavaScript
29
star
4

calypso

A common query interface for data stores, featuring a SQL-like query language.
JavaScript
20
star
5

siren-api-browser

A browser for Siren APIs.
JavaScript
19
star
6

spego

A set of policies for Open Policy Agent to validate OpenAPI definitions.
Open Policy Agent
18
star
7

leisure

Add hypermedia awareness to your REST services.
JavaScript
16
star
8

NRack

A .NET port of Ruby's Rack framework
C#
12
star
9

request-caching

An HTTP client with caching, built on top of request.
JavaScript
10
star
10

node-siren

A Node.js client for the Siren hypermedia type.
JavaScript
9
star
11

hypermedia-type

A Node.js module exporting a map of common hypermedia names to registered IANA media type names.
JavaScript
9
star
12

refine

A lightweight, extensible object query tool for JavaScript / JSON objects.
JavaScript
8
star
13

newman-debug

A guide and example project showing how to debug Postman collection scripts with newman.
6
star
14

apigee-hcl

An HCL syntax to configure Apigee proxies.
Go
5
star
15

sassy-crm

Example application demonstrating REST and CQRS.
CoffeeScript
5
star
16

Tabasco

A simple Web framework that drops a little spice on top of NRack.
C#
5
star
17

picohttpparser-sys

Rust bindings to a tiny HTTP parser written in C (https://github.com/h2o/picohttpparser).
Rust
5
star
18

node-ntlm-client

An NTLM client for Node.js
JavaScript
4
star
19

revolt

A reactive, pipelined HTTP client.
JavaScript
4
star
20

caql-js-compiler

A CaQL compiler that converts queries into executable JavaScript.
JavaScript
4
star
21

surface

JavaScript
4
star
22

ws2mqtt

A WebSocket proxy to an MQTT broker backend.
JavaScript
3
star
23

calypso-level

A calypso driver for LevelUP-compatible data stores.
JavaScript
3
star
24

apigee-edgemicro-docker

Dockerize Apigee Edge Microgateway
Shell
3
star
25

kube-observable

Watch Kubernetes resources with a resilient RxJS Observable client.
JavaScript
3
star
26

HttpParser

.NET bindings for https://github.com/joyent/http-parser
C#
3
star
27

siren-alps-mapping

A little fun mapping the ALPS specification to Siren.
Makefile
3
star
28

siren-alps

A Siren implementation of ALPS.
JavaScript
2
star
29

caql

Calypso Query Language Parser & AST
JavaScript
2
star
30

sirenlint

A lint tool for validating Siren (http://sirenspec.org).
JavaScript
2
star
31

siren-api-testing

This is an example of testing a Siren API using Node.js
JavaScript
2
star
32

express-gateway-plugin-http-cache

An HTTP-aware cache for Express Gateway.
JavaScript
2
star
33

api-media-type

A Node.js module exporting a map of common media type names to registered IANA media type names. Built specifically to serve the needs of Web APIs.
JavaScript
2
star
34

calypso-usergrid

A Usergrid session for Calypso.
JavaScript
2
star
35

hrclgbtq2020-server

This is a GraphQL server driven by data from the Human Rights Campaign - State Equality Index 2020 Report.
HTML
2
star
36

level-caql

Adds CaQL query support to LevelUP.
JavaScript
2
star
37

issue-tracker-hypermedia-example

An example hypermedia API server demonstrating support for multiple hypermedia types. API domain based on the work of https://github.com/webapibook/issuetracker.
JavaScript
2
star
38

express-gateway-plugin-compression

A plugin for Express Gateway enabling content compression.
JavaScript
1
star
39

docker-node-curl-jq

A Docker image with Node.js, curl, and jq.
Shell
1
star
40

revolt-gzip

GZip compression support for revolt (https://github.com/kevinswiber/revolt).
JavaScript
1
star
41

ucl-sys

Rust bindings to libucl.
Rust
1
star
42

revolt-json-parser

JSON parser middleware for revolt (https://github.com/kevinswiber/revolt).
JavaScript
1
star
43

spectral-function-past-tense

Test values in Spectral to ensure the text is in past-tense. Good for ensuring events in AsyncAPI and other use cases.
JavaScript
1
star
44

http-telemetry

A library for intercepting HTTP telemetry signals from Node.js
TypeScript
1
star
45

data-media-type

A Node.js module for finding IANA registered names for common data types.
JavaScript
1
star
46

api-craft-moustachio

Code for the December JavaScript-focused API Craft
JavaScript
1
star
47

medea-caql

Adds CaQL query support to Medea.
JavaScript
1
star
48

calypso-memory

An in-memory representation for Calypso.
JavaScript
1
star
49

calypso-mongodb

A MongoDB driver for Calypso.
JavaScript
1
star
50

zetta-arduino-mqtt

An example of using Arduino with Zetta via MQTT.
JavaScript
1
star
51

homebrew-postmanctl

Homebrew tap for postmanctl
Ruby
1
star
52

oxide

Reactive JavaScript
JavaScript
1
star
53

openapi-from-scratch

JavaScript
1
star
54

zetta-dot-net

Create Zetta Drivers and Scouts using C#.
C#
1
star
55

loopback-connector-manta

A LoopBack connector for Manta.
JavaScript
1
star
56

zetta-hue-clock

This is a small Zetta app that changes Philips Hue bulb colors according to the current time.
JavaScript
1
star
57

learner-api

Postman API Learner
Shell
1
star
58

harviz

Visualize HAR files right in your terminal.
Shell
1
star
59

picohttpparser-rs

A Rust-friendly interface over picohttpparser-sys.
Rust
1
star
60

spectral-custom-function-example

Temporary repo to demonstrate hosted Spectral rulesets.
JavaScript
1
star
61

zetta-docker-driver

Monitor Docker containers as Zetta devices.
JavaScript
1
star
62

NRack.Mashups

Twisting languages around NRack on the .NET platform.
C#
1
star
63

swiberdev-kube-postman-1

An example repository to demonstrate deploying to Kubernetes from a Postman collection.
HTML
1
star