Skip to content

API: Apply 'pipeline' refactor to the other endpoints #5508

@ErisDS

Description

@ErisDS

In 51ac3f6 I refactored the post, user and tag endpoints to use our pipeline promise utility.

This means that serving an API request becomes a matter of taking inputs (either just options, or object & options) and passing them through a series of functions which either return a value or a promise for a value. The output form one function is passed as the argument to the next, forming a chain somewhat similar to a middleware stack.

If at any step, there is an error or promise rejection, the pipeline returns an error, meaning that validation, permission handling, and data fetching can all be steps which return their own errors and prevent the process from continuing if they go wrong.

The best thing about this approach is that it wraps individual lines of endpoint code in functions which describe what happens, like validation and handlePermissions rather than having a large block of promise code. This has reduced the codeclimate score, as the vast amounts of code duplication are now obvious, whereas before they were hidden by lines being in slightly different orders.

It would be great to continue rolling out this refactor across the other endpoints. This could be done as a single task, or as one PR per endpoint - some of them are trickier than others (and in rough order of priority):

  • Posts
  • Users
  • Tags
  • Settings
  • Authentication
  • Roles
  • Configuration (too simple to need it)
  • Themes
  • Upload
  • Slugs
  • Notifications
  • DB
  • Mail

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects:apiAffects the Ghost APIaffects:serverIssues relating to the server or core of Ghosthelp wanted[triage] Ideal issues for contributors to help with

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions