Skip to content

[FR] JSON:API compliance - links #21

@MaSpeng

Description

@MaSpeng

Is your feature request related to a problem? *

From my current point of view, this library does not allow to add other links, besides pagination, then self or related to the document or resource. The JSON:API specification does not describe a restriction to this.

As an example, it is not possible to describe an API entry point that only contains links and might also contain document metadata.

Describe the solution you'd like*

I could imagine, that the properties document and resource in the linkers option will allow a map containing the link names, self as an example, as the key, and the Linker as the value.

Example:

return new Serializer('', {
  version: null,
  linkers: {
    document: {
      self: new Linker(() => 'https://example.com/api'),
      resource: new Linker() => 'https://example.com/api/resources').
    },
  },
  metaizers: {
    document: new Metaizer(() => ({
      foo: 'bar',
    })),
  },
}).serialize(undefined);

Another solution might be that the Linker could return a map of links:

Example:

return new Serializer('', {
  version: null,
  linkers: {
    document: new Linker(() => ({
      self: 'https://example.com/api',
      resource: 'https://example.com/api/resources'
    })),
  },
  metaizers: {
    document: new Metaizer(() => ({
      foo: 'bar',
    })),
  },
}).serialize(undefined);

Describe alternatives you've considered*

Serializing resources with other links by hand or amending the serialization result.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions