-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
API: Apply 'pipeline' refactor to the other endpoints #5508
Comments
refs TryGhost#5508 - adds pipeline to the add and destroy methods of the notifications api
I'd like to pick this one up and finish the parts, that are unchecked. I think a refactoring to |
This issue is almost done, with the exception of upload (#6648) and settings (#6028). Upload I think is close, but the tests possibly need some work. Particularly to do with the change from I've tried to update, fixup & rebase #6028 but am not feeling confident with it yet. If anyone else fancies a stab grab it, else I'll try again soon. |
I'm closing most API issues temporarily with the JSON API Overhaul & OAuth access are currently scheduled next on the roadmap |
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
, orobject
&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
andhandlePermissions
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):
Configuration(too simple to need it)The text was updated successfully, but these errors were encountered: