Skip to content

HAL's _links is not always [String:[String:AnyObject]] #27

@orta

Description

@orta

If you use curies then the _links in HAL-compatible JSON looks like this:

  "_links": {
    "curies": [
      {
        "name": "image",
        "href": null,
        "templated": true
      }
    ],
    "thumbnail": {
      "href": "https://d32dm0rphc51dk.cloudfront.net/Bzp0BLipfnPU1hd6DHyHJw/medium.jpg"
    },
    "image:self": {
      "href": "{?image_version}.jpg",
      "templated": true
    },
    "self": {
      "href": "https://api.artsy.net/api/shows/4ea19ee97bab1a0001001908"
    },
    ...

which means that:

/// A function to deserialize a HAL structure into a HTTP Transition.
public func deserializeHAL(hal:[String:AnyObject]) -> Representor<HTTPTransition> {
  var hal = hal

  var links = [String:HTTPTransition]()
  if let halLinks = hal.removeValueForKey("_links") as? [String:[String:AnyObject]] {
    links = parseHALLinks(halLinks)
  }

Fails at if let halLinks = hal.removeValueForKey("_links") as? [String:[String:AnyObject]] {.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions