Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/docs/reference/functions/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ Functions can be written in JavaScript or Typescript.
```ts:title=src/api/typescript.ts
import { GatsbyFunctionRequest, GatsbyFunctionResponse } from "gatsby"

interface ContactBody {
message: string
}

export default function handler(
req: GatsbyFunctionRequest,
req: GatsbyFunctionRequest<ContactBody>,
res: GatsbyFunctionResponse
) {
res.send(`I am TYPESCRIPT`)
res.send({ title: `I am TYPESCRIPT`, message: req.body.message })
}
```

Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ export interface GatsbyFunctionResponse<T = any> extends ServerResponse {
/**
* Gatsby function route request
*/
export interface GatsbyFunctionRequest extends IncomingMessage {
export interface GatsbyFunctionRequest<ReqBody = any> extends IncomingMessage {
/**
* Object of values from URL query parameters (after the ? in the URL)
*/
Expand All @@ -1658,7 +1658,7 @@ export interface GatsbyFunctionRequest extends IncomingMessage {
* Object of values from route parameters
*/
params: Record<string, string>
body: any
body: ReqBody
/**
* Object of `cookies` from header
*/
Expand Down