#Functions as endpoints?

1 messages · Page 1 of 1 (latest)

delicate cedar
#

Does anyone know a library or have an idea as to if it's possible to have functions act as endpoints?

So basically:

  • The function params would be automatically "registered"/filled when someone makes a post request => no need to manually parse the params from the request body
  • On the client, I'd need to make a fetch to that endpoint generated from the function - as always. But on the server, I should be able to just call the function without having to make a fetch. That way, I wouldn't have to extract the endpoint logic into a function, which would simplify things

Any thoughts? Could that be possible`?

silent rock
# delicate cedar Does anyone know a library or have an idea as to if it's possible to have functi...

I was thinking about something along those lines, like having an actions field next to hooks etc. While I think there certainly is a use case for that I was afraid it might convolute the collection configs and typing all this would become difficult. Also it is not 100% clear how to infer endpoints from functions automatically (what is the correct http verb? what would be the best url?)
Still like the idea overall 🙂

delicate cedar
#

I think Spring does that through annotations! But that's more a black magic solution I guess

#

Why an actions field though? I was thinking of just being able to pass a function into endpoints

#

then have some wrapper which somehow reads that function's parameters to generate an endpoint which calls that function

drifting wolf
#

I don't see how you could run it separately without extracting the function right now...though you could write something that's then re-usable for this very thing no?

i thought about calling the handler directly, well actually you could have a function that returns a handler (or not) depending on the params

drifting wolf