Skip to content

Commit c2b75f8

Browse files
authored
Merge pull request spinframework#30 from karthik2804/fix/http_response
fix httprequest type so proper headers are set on responses
2 parents c516765 + 5c60d81 commit c2b75f8

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

crates/spin-js-engine/src/js_sdk/modules/spinSdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface HttpRequest extends SpinHttpRequest {
1919

2020
interface HttpResponse {
2121
status: number
22-
headers: Map<string, string>
22+
headers: Record<string, string>
2323
body?: ArrayBuffer
2424
}
2525

examples/typescript/hello_world/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { HandleRequest, HttpResponse } from "spin-sdk-types"
22

33
const encoder = new TextEncoder()
44

5-
export const handleRequest: HandleRequest = async function(request): Promise<HttpResponse> {
5+
export const handleRequest: HandleRequest = async function (request): Promise<HttpResponse> {
66

7+
78
return {
89
status: 200,
9-
headers: new Map([[ "foo", "bar" ]]),
10+
headers: {"foo": "bar"},
1011
body: encoder.encode("Hello from JS-SDK").buffer
1112
}
1213
}

examples/typescript/outbound-http/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {HandleRequest, HttpResponse} from "spin-sdk-types"
1+
import { HandleRequest, HttpResponse } from "spin-sdk-types"
22

33
const encoder = new TextEncoder()
44
const decoder = new TextDecoder()
55

6-
export const handleRequest: HandleRequest = async function(request): Promise<HttpResponse> {
6+
export const handleRequest: HandleRequest = async function (request): Promise<HttpResponse> {
77

88
const dogFact = await fetch("https://some-random-api.ml/facts/dog")
99

@@ -15,7 +15,7 @@ export const handleRequest: HandleRequest = async function(request): Promise<Htt
1515

1616
return {
1717
status: 200,
18-
headers: new Map([[ "foo", "bar" ]]),
18+
headers: { "foo": "bar" },
1919
body: encoder.encode(body).buffer
2020
}
2121
}

examples/typescript/planetscale/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const handleRequest: HandleRequest = async function(request): Promise<Htt
2222

2323
return {
2424
status: 200,
25-
headers: new Map([[ "foo", "bar" ]]),
25+
headers: { "foo": "bar" },
2626
body: encoder.encode(body).buffer
2727
}
2828
}

templates/http-ts/content/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const encoder = new TextEncoder()
55
export const handleRequest: HandleRequest = async function(request): Promise<HttpResponse> {
66
return {
77
status: 200,
8-
headers: new Map([[ "foo", "bar" ]]),
8+
headers: { "foo": "bar" },
99
body: encoder.encode("Hello from TS-SDK").buffer
1010
}
1111
}

types/lib/modules/spinSdk.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface HttpRequest extends SpinHttpRequest {
1313
}
1414
interface HttpResponse {
1515
status: number;
16-
headers: Map<string, string>;
16+
headers: Record<string, string>;
1717
body?: ArrayBuffer;
1818
}
1919
declare type HandleRequest = (request: HttpRequest) => Promise<HttpResponse>;

0 commit comments

Comments
 (0)