Skip to content

Commit

Permalink
Merge pull request #1271 from VamshiReddy02/type-code
Browse files Browse the repository at this point in the history
Replacing python code with typescript in spin docs
  • Loading branch information
Timothy McCallum authored May 7, 2024
2 parents c534969 + 972b98d commit e01009f
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions content/spin/v2/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,25 @@ fn handle_spin_example(req: Request) -> Result<impl IntoResponse> {
> Note that the name is `Config` rather than `Variables`.
```ts
from spin_sdk import http
from spin_sdk.http import Request, Response
from spin_sdk import variables

class IncomingHandler(http.IncomingHandler):
def handle_request(self, request: Request) -> Response:
password = request.body.decode("utf-8")
expected = variables.get("password")
access = "denied"
if expected == password:
access = "accepted"
response = f'\{{"authentication": "{access}"}}'
return Response(
200,
{"content-type": "text/plain"},
bytes(response, "utf-8")
)
import { HandleRequest, HttpRequest, HttpResponse, Config } from "@fermyon/spin-sdk"

const decoder = new TextDecoder("utf-8")

export const handleRequest: HandleRequest = async function (request: HttpRequest): Promise<HttpResponse> {
const expected = decoder.decode(request.body)
let password = Config.get("password")
let access = "denied"
if (expected === password) {
access = "accepted"
}
let responseJson = `{\"authentication\": \"${access}\"}`;

return {
status: 200,
headers: { "Content-Type": "application/json" },
body: responseJson
}
}
```

{{ blockEnd }}
Expand Down

0 comments on commit e01009f

Please sign in to comment.