GSoC 2019 Coding Period Week 8

By Loong

Since the JSON:API code base is very large, after copying the jsonapi module into the wotapi code base, I deleted a lot of things, such as the Query folder, but it was not enough. Cutting out the code base makes it easier for me to move forward.


This is one endpoint of the jsonapi to the listing route to get a list of entities. All I need is a Thing Entity, and everything else is indexed to it based on a Thing Entity. The representation in the routing list is that the base path is /things.

I found that the earliest addition of base path /jsonapi was at Remove configurable ‘prefix’ + change the non-configurable prefix from ‘/api’ to ‘/jsonapi’. But prefix /api added to the jsonapi code base in commit 54feb2f6eeb21bfefdaa0c61e45d629f12c1c5dd. I can’t find any more discussion of the prefix. What worries me is: if there is no base path, will come up against duplication of route issue? I think I should keep prefix as this ensures won’t come up duplication of route issues. But I need to change the /jsonapi to /wotapi.


The JSON:API generates the resource path by /entity_type_id/bundle. See getPath()

   * Get the resource path.
   * @return string
   *   The path to access this resource type. Default: /entity_type_id/bundle.
   * @see jsonapi.base_path
  public function getPath() {
    return sprintf('/%s/%s', $this->getEntityTypeId(), $this->getBundle());

There is no such thing as /entity_type_id/bundle at, so I need to find out why the jsonapi module is designed this way. And it is likely that the resource path of the /entity_type_id/bundle design will still be used.

An example of a resource path on


An example of a resource path on


I found the record of getPath() method at Make the resource type aware of the resource path. But the actual design was: [FEATURE] Move the resources to /{entity_type_id}/{bundle}/{id}

In order to resolve #2735665: [BUGFIX] Name collision with bundles with same name we need to move the bundle level resources namespaced under the entity type.

In fact, all we really need the entity type only Thing, so we’re not going to have a bundle duplicate name problem. To make Things easier to read, I need to change the getPath() method. But what about other resources that might be referenced by Things?

public function getPath() {
  $entity_type_id = $this->getEntityTypeId();
  switch ($entity_type_id){
    case "wotapi_thing":
    case "wotapi_property":
      return "/properties";
      return sprintf('/%s/%s', $entity_type_id, $this->getBundle());

Access all Things resources:


Get a single Thing resource:


I need to change route behavior. The URL of obtaining Property resource described in the Web Thing API specification includes /properties/, but JOSNAPI obtaining relationships resource content is not included /relationships. I copy from JSONAPI to the getIndividualRoutesForResourceType() method, so I only need to change the part of this method can achieve a goal.


After change getIndividualRoutesForResourceType() method. According to the current data, I can only get the name of the property from the URL.


Based on the description of the ID, I’m going to get it from the URI.