File tree 2 files changed +8
-4
lines changed
docs/docs/reference/functions 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -48,11 +48,15 @@ Functions can be written in JavaScript or Typescript.
48
48
``` ts:title=src/api/typescript.ts
49
49
import { GatsbyFunctionRequest , GatsbyFunctionResponse } from " gatsby"
50
50
51
+ interface ContactBody {
52
+ message: string
53
+ }
54
+
51
55
export default function handler(
52
- req : GatsbyFunctionRequest ,
56
+ req : GatsbyFunctionRequest < ContactBody > ,
53
57
res : GatsbyFunctionResponse
54
58
) {
55
- res .send (` I am TYPESCRIPT ` )
59
+ res .send ({ title: ` I am TYPESCRIPT ` , message: req . body . message } )
56
60
}
57
61
```
58
62
Original file line number Diff line number Diff line change @@ -1648,7 +1648,7 @@ export interface GatsbyFunctionResponse<T = any> extends ServerResponse {
1648
1648
/**
1649
1649
* Gatsby function route request
1650
1650
*/
1651
- export interface GatsbyFunctionRequest extends IncomingMessage {
1651
+ export interface GatsbyFunctionRequest < ReqBody = any > extends IncomingMessage {
1652
1652
/**
1653
1653
* Object of values from URL query parameters (after the ? in the URL)
1654
1654
*/
@@ -1658,7 +1658,7 @@ export interface GatsbyFunctionRequest extends IncomingMessage {
1658
1658
* Object of values from route parameters
1659
1659
*/
1660
1660
params : Record < string , string >
1661
- body : any
1661
+ body : ReqBody
1662
1662
/**
1663
1663
* Object of `cookies` from header
1664
1664
*/
You can’t perform that action at this time.
0 commit comments