Skip to content

Act like a REST client #34

Description

@dennisvang

The FDP spec mentions that the API must be REST compliant (which actually implies HATEOAS):

The API of the FDP follows the REST HATEOAS (Hypermedia as the Engine of Application State) guidelines by providing information so that the client is able to discover the available actions and access the resources it needs. [...]

Unfortunately the actual FDP reference implementation does not provide proper HATEOAS support, because it does not list allowable state transitions in every API response (like links on a web page). The specs do indicate that the RDF navigation information serves this purpose, but this is not the same thing, and it is at best incomplete.

However, the reference implementation does provide OpenAPI docs, at the /v3/api-docs path, which describe the API contract.
This information can still be used to make the client a bit more robust.

Currently, the client hard-codes the API paths, for example

https://github.com/FAIRDataTeam/FAIRDataPoint-client-redux/blob/91638ad338dc1b56ecaf889c18e8d99af05a3ee6/src/composables/fdpApi.ts#L45

One of the first things to do is get rid of all hard-coded URL path patterns, except for the root and/or /v3/api-docs paths.
Instead, we could start by getting the api-docs, extracting the available "operations" and mapping them to the corresponding paths.

So, instead of hard-coding the paths, we then hard-code the operationIds, and get the corresponding paths and parameters from the api-docs. This makes the client more robust w.r.t. future changes in the API contract, and it also prepares the ground for a future HATEOAS compliant API.

For example, from the api-docs below we can map the generateToken operation to the /tokens path, and could also extract information about parameters, request body, etc.:

{
  "openapi" : "3.1.0",
  ...,
  "paths" : {
    ...,
    "/tokens" : {
      "post" : {
        "tags" : [ "Authentication and Authorization" ],
        "operationId" : "generateToken",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/AuthDTO"
              }
            }
          },
          "required" : true
        },
        ...
      }
    },
    ...
  },
  ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions