fermyon / spin-js-sdk

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

make return type flexible #115

Closed karthik2804 closed 1 year ago

karthik2804 commented 1 year ago

This PR allows the return type to be more flexible on the body parameter

export async function handleRequest(request) {

    return {
        status: 200,
        headers: { "foo": "bar" },
        body: "Hello from JS-SDK"
    }
}

This PR also adds a new handler function signature handler(req, res) which allows creating responses using chaining

import { EventHandler, HttpRequest, HttpResponse } from "spin-sdk"

export const eventHandler: EventHandler = async function (request: HttpRequest, response: ResponseObject): Promise<void> {

    response.status(200).header("content-type", "text/html").body("Chaining works")
}

Signed-off-by: karthik Ganeshram karthik.ganeshram@fermyon.com

karthik2804 commented 1 year ago

Will move the implementation of the alternate function signature to a separate PR.