Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

[Question] Feature consumed by both API and Web #2

@yasalkhatib

Description

@yasalkhatib

Hello,
Thank you for this well explained demo of Lucid.

I have a question regarding RespondWithJsonJob and RespondWithViewJob.

If my feature should serve both API and Web Controllers. They have exactly the same logic except for the last line which returns either JSON or a view.

What is your recommended solution here?

I am thinking about creating a Middleware where I inject into the Request object a value (e.g. source [WEB, API]) which determines whether the request is an API or Web.
And then inside the feature, I have two options:

  1. Create an Operation e.g. RespondOperation, that takes the source variable, and based on that, it will run either RespondWithJsonJob or RespondWithViewJob.
  2. Add if; else inside the feature to determine which response job based on the source.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions