Define API URI naming conventions

Created on 3 September 2024, 8 months ago

Problem/Motivation

Our API endpoint URIs are currently ad hoc and inconsistent, e.g., /api/layout/..., /xb-components, and /xb/api/.... We need a stable, predictable convention.

Proposed resolution

Create a convention that observes generally-accepted industry standards and respects Drupal-specific conventions:

REST API URI Naming Conventions and Best Practices has a good overview.

We need to make sure we don't collide or conflict with other common patterns or solutions in Drupal. For example, it would be begging for problems to do anything under /api/, which someone somewhere is surely already using. We should also avoid /xb/ if we're going to use that path for administrative UI routes.

We should also consider any other paths the module uses and make sure all of them make sense together.

Finally, I think it's worth considering versioning the API, e.g., .../v1/...--a common practice. We may conclude it's superfluous, but we should still consider it.

I could imagine, for example, something like this:

/xb-api/v1/{resources} [/{resourceId} [/{subCollections} [ /{resourceId} ] ] ]
<!--<h3 id="summary-remaining-tasks">Remaining tasks</h3>--><!--<h3 id="summary-api-changes">API changes</h3>--><!--<h3 id="summary-data-model-changes">Data model changes</h3>-->
๐Ÿ“Œ Task
Status

Active

Component

Page builder

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States traviscarden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @traviscarden
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States traviscarden
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States traviscarden
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    WFM in general, with one exception:

    /xb-api/v1/{resources} [ /{resourceId} [ /{subCollections} [ /{resourceId} ] ] ]

    -1 to versioning the API at this time, because that implies it's a public API. It is not. Defining a public API for this that we provide BC for is definitely not in scope.

    If you really want to have it, then let's use:

    /xb-api/v0/{resources} [ /{resourceId} [ /{subCollections} [ /{resourceId} ] ] ]

    (with v0 matching XB's major version: 0.x)

    P.S.: I do not understand why

    We should also avoid /xb/ if we're going to use that path for administrative UI routes.

    matters? /xb-api/โ€ฆ vs /xb/api/โ€ฆ are essentially the same?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States effulgentsia

    Instead of /v0/, perhaps we can make it even clearer that it's an internal API by naming it /internal/?

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    #5++

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States traviscarden

    Re: versioning the API, I only proposed it to consider because it's a common industry pattern. If we're not making any stability promises for contrib modules to use it, for example, I see no reason for it. In that case, I don't think we need /internal/ either.

    As to avoiding /xb/, I wanted to prevent "namespace" collisions, since we already have some routes at /xb/. But having considered it a little more, I don't think I'm actually worried about it as long as we don't anticipate wanting to use /xb/api/ for anything else. In fact, there would be a certain elegance in it if we can keep everything under /xb/. Perhaps we could do something like /xb/api/ and /xb/routes/ or similar.

    I'm updating the issue description accordingly.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    I agree with @traviscarden - versioning is a standard practice. It also means we can evolve over time. If we decide the API for an endpoint changes, we start a new version and emit deprecations from the old one.

    Another alternative practise is to require consumers to set the version # via an accept header - e.g. github has Accept: application/vnd.github.v3+json

    I think it's easier to just put it in the URL, so plus one for v0

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    The URI naming was made consistent in ๐Ÿ“Œ Make all XB HTTP API routes consistently prefixed Active ๐Ÿ˜„

    That also means that versioning it today would be trivial.

    @traviscarden, would you like to take that on? :D

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States traviscarden

    On it, @wim leers!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States traviscarden

    I started to create a static helper to centralize the path generation logic (because it is a little inconsistent), but most of the API path strings were in YAML and JavaScript files, so once I decided not to use it in test classes (because it would make them less expressive), there weren't enough uses left to justify its existence. I'm basically explaining why I didn't have an MR in the 5 minutes it took to do a search-and-replace. ๐Ÿ˜› Anyway, here it is. ^

  • Assigned to wim leers
  • Status changed to Needs review 29 days ago
  • First commit to issue fork.
  • Pipeline finished with Failed
    29 days ago
    Total: 1570s
    #473116
  • Pipeline finished with Failed
    26 days ago
    Total: 1659s
    #476188
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Thanks!

  • Pipeline finished with Failed
    25 days ago
    Total: 2086s
    #476634
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States partyka

    There's another merge conflict, working on resolving it.

  • Pipeline finished with Failed
    25 days ago
    Total: 1775s
    #476790
  • Pipeline finished with Failed
    25 days ago
    Total: 2018s
    #476816
  • Pipeline finished with Failed
    25 days ago
    Total: 2905s
    #476852
  • Pipeline finished with Failed
    18 days ago
    Total: 612s
    #482009
  • Pipeline finished with Failed
    18 days ago
    Total: 541s
    #482032
  • Pipeline finished with Failed
    18 days ago
    Total: 943s
    #482203
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    DxRouteConsistencyTest is not currently passing โ€” once it is, I'm looking forward to merging this, and I'm sure @larowlan does too ๐Ÿ˜„

  • First commit to issue fork.
  • Pipeline finished with Failed
    14 days ago
    Total: 677s
    #484501
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Thanks so much! Letโ€™s land this today so yโ€™all can stop chasing HEAD! ๐Ÿ™ˆ

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Pipeline finished with Skipped
    14 days ago
    #484785
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024