You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a few elements to this so I'll try and break this down - the main use case here is to be able to build full REST based applications.
1. Routing
This may already exist but couldn't really find it, when defining your functions in yml - you would ideally want to specify a path and method exclusively for that function. There would need to be some validation somewhere so that 2 or more functions can't specify the same combination. An example of what this may look like;
If the user tries to GET /login then the gateway should return a 405 Method Not Allowed (unless the relevant method is allowed).
2. Parameters
Named parameters make searches or model lookups a lot more friendly (than say, using query strings) - it's easy to see exactly what's happening within the URL, for example;
GET /api/categories/my-category/posts
It's obvious that we're getting all the posts from my-category but, we'd ideally want that to be named going into the function. An example yml may look like;
I'm not sure how the gateway would pass that into the function, perhaps query string it into the function? Then each function/language can use it's relevant input library to obtain that information (if that were a solution, it would have to merge with any query strings being passed through too).
I'm not sure how close or far away this is to this issue; #716
3. Middleware
Middleware definitions would allow for generic application code to be run on any other function - AWS's Gateway supports this to authentication only but, I think we could easily expand this in a generic way.
I'll give an example of what this may look like in the yml;
That way, we'll always run the authentication-middleware and access-middleware functions whenever we call the category-posts, we should forward the headers to the middleware functions so that they can action however they need to, and if they return anything other than a 200 we should forward the response to the user and stop processing the chain.
Final Thoughts
All of this could be achieved in the application level, I've been looking at experimenting with nginx + a function that would proxy the other functions (then OpenFaaS would at least be scaling the application gateway) but, maybe it would be nice to actually implement this into OpenFaaS itself natively.
This would give enough flexibility to be a full REST platform and be more flexible than the alternatives (especially with multi-middleware capabilities). Unfortunately I don't have enough Go (if any) knowledge to be able to PR this but happy to advise.
The text was updated successfully, but these errors were encountered:
alexellis
changed the title
Allow functions to be REST driven
Proposal: Custom route support and middleware plugins
Jul 21, 2018
There's a few elements to this so I'll try and break this down - the main use case here is to be able to build full REST based applications.
1. Routing
This may already exist but couldn't really find it, when defining your functions in yml - you would ideally want to specify a path and method exclusively for that function. There would need to be some validation somewhere so that 2 or more functions can't specify the same combination. An example of what this may look like;
If the user tries to GET /login then the gateway should return a 405 Method Not Allowed (unless the relevant method is allowed).
2. Parameters
Named parameters make searches or model lookups a lot more friendly (than say, using query strings) - it's easy to see exactly what's happening within the URL, for example;
It's obvious that we're getting all the posts from
my-category
but, we'd ideally want that to be named going into the function. An example yml may look like;I'm not sure how the gateway would pass that into the function, perhaps query string it into the function? Then each function/language can use it's relevant input library to obtain that information (if that were a solution, it would have to merge with any query strings being passed through too).
I'm not sure how close or far away this is to this issue; #716
3. Middleware
Middleware definitions would allow for generic application code to be run on any other function - AWS's Gateway supports this to authentication only but, I think we could easily expand this in a generic way.
I'll give an example of what this may look like in the yml;
That way, we'll always run the
authentication-middleware
andaccess-middleware
functions whenever we call thecategory-posts
, we should forward the headers to the middleware functions so that they can action however they need to, and if they return anything other than a 200 we should forward the response to the user and stop processing the chain.Final Thoughts
All of this could be achieved in the application level, I've been looking at experimenting with nginx + a function that would proxy the other functions (then OpenFaaS would at least be scaling the application gateway) but, maybe it would be nice to actually implement this into OpenFaaS itself natively.
This would give enough flexibility to be a full REST platform and be more flexible than the alternatives (especially with multi-middleware capabilities). Unfortunately I don't have enough Go (if any) knowledge to be able to PR this but happy to advise.
The text was updated successfully, but these errors were encountered: