Skip to content
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

"Request Tranformer" middleware #1013

Closed
vascanera opened this issue Feb 6, 2024 · 2 comments
Closed

"Request Tranformer" middleware #1013

vascanera opened this issue Feb 6, 2024 · 2 comments
Assignees

Comments

@vascanera
Copy link

vascanera commented Feb 6, 2024

Hi Maurits & all,
Would it be possible (what would be the effort level?) to implement a "request transformer" middleware so that we could have a function (executed first among the middlewares) that receives the global Request object as the input, transforms it as desired, and then return a modified (transformed) request object that the API will use from here on for the current process?

This would solve the case of masking (hiding) implementation details of a url route on the client side without resorting to other frameworks / libraries (the last piece of the puzzle for building really nice custom API routes using just this awesome lib).

Example:
On the client, when I click a submit button, I don't want the url to show sensitive data, like real user ids or real column names as they are stored in the database.
I would like to access: api/users/f3xh4hc33a instead of api.php/records/users/3
The API would need to be aware of this request and use if for subsequent operations (and not use the global Request object) from this point on until finishing the current process.
Such function could look something like:

function transformRequest ($originalRequest) { 
     $transformedRequest = $originalRequest;
     // ...;
     // ... split request into parts; 
     // ... transform request parts as required;
     $transformedRequest.url = '/records/users/3'; 
     $transformedRequest.method = 'POST'; 
     // ...;

     return $transformedRequest;
}
@mevdschee
Copy link
Owner

mevdschee commented Feb 6, 2024

Hi @vascanera, My understanding is that what you want is exactly what the customization.beforeHandler is designed to facilitate, see:

$result = call_user_func($beforeHandler, $operation, $tableName, $request, $environment);

Kind regards, Maurits

@mevdschee mevdschee self-assigned this Feb 6, 2024
@vascanera
Copy link
Author

You are absolutely right, that is exactly what I need. How in the world did I miss that part from the docs?...
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants