Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a single API entrypoint #1

Open
baddlan opened this issue Apr 11, 2017 · 0 comments
Open

Creating a single API entrypoint #1

baddlan opened this issue Apr 11, 2017 · 0 comments

Comments

@baddlan
Copy link

baddlan commented Apr 11, 2017

The Api-platform REST Admin makes a few requests to gather the services metadata before building its interface including the navigation
menu. It expects the root URL to return a basic list of services with an Entrypoint context.

http://api.ds.ca/

{
  "@context": "/contexts/Entrypoint",
  "@id": "/",
  "@type": "Entrypoint",
  "case": "/cases"
}

The Entrypoint context itself is called to fetch the URL of the JSON-LD Docs.

http://api.ds.ca/contexts/Entrypoint

{
  "@context": {
    "@vocab": "http://api.ds.ca/docs.jsonld#",
    "hydra": "http://www.w3.org/ns/hydra/core#",
    "case": {
      "@id": "Entrypoint/case",
      "@type": "@id"
    }
  }
}

The JSON-LD Docs file describes, in details, all the entrypoints that will be listed in the navigation
as well as the properties and operations of the microservices.

http://api.ds.ca/docs.jsonld

{
  "@context": {
    "@vocab": "http://api.ds.ca/docs.jsonld#",
    "hydra": "http://www.w3.org/ns/hydra/core#",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "xmls": "http://www.w3.org/2001/XMLSchema#",
    "owl": "http://www.w3.org/2002/07/owl#",
    "domain": {
      "@id": "rdfs:domain",
      "@type": "@id"
    },
    "range": {
      "@id": "rdfs:range",
      "@type": "@id"
    },
    "subClassOf": {
      "@id": "rdfs:subClassOf",
      "@type": "@id"
    },
    "expects": {
      "@id": "hydra:expects",
      "@type": "@id"
    },
    "returns": {
      "@id": "hydra:returns",
      "@type": "@id"
    }
  },
  "@id": "/docs.jsonld",
  "hydra:title": "Cases",
  "hydra:description": "The DigitalState Cases Api",
  "hydra:entrypoint": "/",
  "hydra:supportedClass": [
    {
      "@id": "#Case",
      "@type": "hydra:Class",
      "rdfs:label": "Case",
      "hydra:title": "Case",
      "hydra:supportedProperty": [
        {
          "@type": "hydra:SupportedProperty",
          "hydra:property": {
            "@id": "#Case/title",
            "@type": "rdf:Property",
            "rdfs:label": "title",
            "domain": "#Case",
            "range": "xmls:string"
          },
          "hydra:title": "title",
          "hydra:required": true,
          "hydra:readable": true,
          "hydra:writable": true
        }
      ],
      "hydra:supportedOperation": [
        {
          "@type": "hydra:Operation",
          "hydra:method": "GET",
          "hydra:title": "Retrieves Case resource.",
          "rdfs:label": "Retrieves Case resource.",
          "returns": "#Case"
        },
        {
          "@type": "hydra:ReplaceResourceOperation",
          "expects": "#Case",
          "hydra:method": "PUT",
          "hydra:title": "Replaces the Case resource.",
          "rdfs:label": "Replaces the Case resource.",
          "returns": "#Case"
        },
        {
          "@type": "hydra:Operation",
          "hydra:method": "DELETE",
          "hydra:title": "Deletes the Case resource.",
          "rdfs:label": "Deletes the Case resource.",
          "returns": "owl:Nothing"
        }
      ],
      "hydra:description": "Class CaseEntity"
    },
    {
      "@id": "#Entrypoint",
      "@type": "hydra:Class",
      "hydra:title": "The API entrypoint",
      "hydra:supportedProperty": [
        {
          "@type": "hydra:SupportedProperty",
          "hydra:property": {
            "@id": "#Entrypoint/case",
            "@type": "hydra:Link",
            "domain": "#Entrypoint",
            "rdfs:label": "The collection of Case resources",
            "range": "hydra:PagedCollection",
            "hydra:supportedOperation": [
              {
                "@type": "hydra:Operation",
                "hydra:method": "GET",
                "hydra:title": "Retrieves the collection of Case resources.",
                "rdfs:label": "Retrieves the collection of Case resources.",
                "returns": "hydra:PagedCollection"
              },
              {
                "@type": "hydra:CreateResourceOperation",
                "expects": "#Case",
                "hydra:method": "POST",
                "hydra:title": "Creates a Case resource.",
                "rdfs:label": "Creates a Case resource.",
                "returns": "#Case"
              }
            ]
          },
          "hydra:title": "The collection of Case resources",
          "hydra:readable": true,
          "hydra:writable": false
        }
      ],
      "hydra:supportedOperation": {
        "@type": "hydra:Operation",
        "hydra:method": "GET",
        "rdfs:label": "The API entrypoint.",
        "returns": "#EntryPoint"
      }
    },
    {
      "@id": "#ConstraintViolation",
      "@type": "hydra:Class",
      "hydra:title": "A constraint violation",
      "hydra:supportedProperty": [
        {
          "@type": "hydra:SupportedProperty",
          "hydra:property": {
            "@id": "#ConstraintViolation/propertyPath",
            "@type": "rdf:Property",
            "rdfs:label": "propertyPath",
            "domain": "#ConstraintViolation",
            "range": "xmls:string"
          },
          "hydra:title": "propertyPath",
          "hydra:description": "The property path of the violation",
          "hydra:readable": true,
          "hydra:writable": false
        },
        {
          "@type": "hydra:SupportedProperty",
          "hydra:property": {
            "@id": "#ConstraintViolation/message",
            "@type": "rdf:Property",
            "rdfs:label": "message",
            "domain": "#ConstraintViolation",
            "range": "xmls:string"
          },
          "hydra:title": "message",
          "hydra:description": "The message associated with the violation",
          "hydra:readable": true,
          "hydra:writable": false
        }
      ]
    },
    {
      "@id": "#ConstraintViolationList",
      "@type": "hydra:Class",
      "subClassOf": "hydra:Error",
      "hydra:title": "A constraint violation list",
      "hydra:supportedProperty": [
        {
          "@type": "hydra:SupportedProperty",
          "hydra:property": {
            "@id": "#ConstraintViolationList/violations",
            "@type": "rdf:Property",
            "rdfs:label": "violations",
            "domain": "#ConstraintViolationList",
            "range": "#ConstraintViolation"
          },
          "hydra:title": "violations",
          "hydra:description": "The violations",
          "hydra:readable": true,
          "hydra:writable": false
        }
      ]
    }
  ]
}

We need to dynamically merge the JSON output of each of those calls by inspecting the output of their counterparts in
each microservice

  • Setup a Docker container with a NginX and PHP. Make sure NginX can read ENV variables in its config file.
    See https://github.com/openresty/docker-openresty
  • The URLs of the microservies are passed to the container in an ENV variable.
  • In NginX, create aliases to /, /docs.jsonld and contexts/Entrypoint so they refer to PHP scripts.
  • Create PHP script(s) to read the microservices URLs from the ENV variable and then fetch the JSON-LD output of the
    URLs mentioned above from each microservice before combining it all together.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant