fermyon / spin-js-sdk

https://developer.fermyon.com/spin/javascript-components
Apache License 2.0
54 stars 18 forks source link

Signature for handler function, response chaining #85

Closed radu-matei closed 1 year ago

radu-matei commented 1 year ago

A usual pattern when writing HTTP handlers in JavaScript is having a function that takes both the request and response, and constructing the response using a builder-like pattern, by chaining the desired status, headers, or body.

An example using Express:

app.get('/', (req, res) => {
    res.status(500).send('Something broke!')
})

This is similar to how other JS frameworks construct HTTP handlers — is this something we'd consider implementing into this SDK?

It is a departure from other Spin SDKs and from the current implementation of this SDK, which takes in the request as a parameter, and returns the response as the result.

karthik2804 commented 1 year ago

Initial prototype in #115