Skip to content

API standards ​

All domain models within Luna should be represented using the industry standard JSON Schema.

This document outlines some of the standards we want to follow for consistency and ease of development.

Documentation ​

All API endpoints should be documented to the OpenAPI 3.0 specification, and can be documented using Swagger.

More details about swagger and the OpenAPI 3.0 specification can be found here: https://swagger.io/specification/

Luna moved off the standalone LunaAPIs CodeCommit repo into the luna monorepo. There is no aggregated, generated OpenAPI spec — each service documents its own endpoints as OpenAPI fragments under its own docs/swagger/ folder (e.g. services/engagements/docs/swagger/), one file per operation.

Useful for creating and validating a swagger file: http://editor.swagger.io/#/

Interface Standards ​

REST Nomenclature

URIs should consist of nouns describing the resource that is being operated on

  • PUT /opportunities/{id} ✅

  • POST /opportunities/{id}/update) ❌

URIs with multiple words should be separate by hyphens - rather than underscores.

  • andis/{id}/career-goals ✅

  • andis/{id}/careerGoals ❌

  • andis/{id}/career_goals ❌

More information on this: https://developers.google.com/search/docs/advanced/guidelines/url-structure

HTTP Methods

HTTP VerbCRUDDescriptionResponse for collection (/andis)Response for singleton (/andis/{id})
POSTCreateCreates a new resource201: ANDi created400: Invalid Operation 409: if resource exists
GETReadGets a resource200: List of ANDis200: Single ANDi 404: Invalid ANDi id
PUTUpdateUpdates an existing resource with full resource representation in the request400: Invalid operation200: ANDi updated 404: Invalid ANDi id
PATCHUpdateUpdates an existing resource with a partial resource representation in the request400: Invalid operation200: ANDi updated 404: Invalid ANDi id
DELETEDeleteDeletes a specific resource400: Invalid operation204: ANDi deleted 404: Invalid ANDi id

Access Patterns

URLDescriptionExampleResult
/<collection>Top level collection/andisA list of ANDis
/<collection>/{id}Specific resource within collection/andis/2ANDi number 2
/<collection>/{id}/<sub-collection>Sub Collection of a specific resource from top level collection/andi/2/skillsANDi number 2’s skills. React, JavaScript, Adaptability
/<collection>/{id}/<sub-collection>/{id}Specific resource within sub- collection/andi/2/skills/reactANDi number2’s react skill. (note: react is the ID for the skill and also the name)

Pagination

Two optional query parameters when getting collections:

limit

  • Defines the maximum number of resources to return at a time

  • Use a default limit if none specified, appropriate for

  • Example: /skills?limit=5 returns the first 5 skills (indexes 0,1,2,3,4)

offset

  • Defines the index of the first resource to include in the response

  • Default is 0

  • Example: /skills?limit=5&offset=5 returns 5 skills, starting at the 5th index (indexes 5,6,7,8,9)

The offset, limit, number of items returned (count) and number of total items (total) should also be returned in a meta tag that is held outside of the object data (where this information would not compromise security).

{
  meta: {
    "offset": 17,
    "limit": 5,
    "count": 4
    "total": 20
  },
  data: {
   ...
  }
}

Sorting

Sorting is done by passing the sort and direction parameters in the request.

If sort is empty then no sorting will be done.

if direction is empty then ascending is assumed.

The sort value is a field for the object.

The direction value can be asc or desc.

Versioning

Versioning is done via the URI, with the version as the first path segment after the host, e.g. GET /v2/contacts, GET /v2/organisations.

Scaffolding ​

Success Responses ​

(2xx Responses)

Returning collections or a specific resource to the user should be done by placing the object within a data object.

Structure:

{
  status: "ok",
  meta: {
    ...
  },
  data: {
    ...
  }
}

Example collection:

{
  status: "ok",
  meta: {
    ...
  },
  data: {
    skills: [ ... ]
  }
}

Example singleton:

{
  status: "ok",
  meta: {
    ...
  },
  data: {
    id: 1,
    name: 'Sam Smith',
    ...
  }
}

Error Responses ​

When returning errors to the user the errors object is always an array containing one or more error objects.

An error object contains:

  • error - which represents the machine error code.

  • message - which represents the human readable message for the user describing the error

Structure:

{
  status: "error",
  errors: [
    {
      error: string,
      message: string
    }
  ]
}

Example

{
  status: "error",
  errors: [
    {
      error: "ValidationError",
      message: "ANDi ID is required"
    }
  ]
}

Made with ❤️ by the Luna team