Types
Elijah Cobb edited this page Apr 30, 2020
·
4 revisions
You can easily require that a request follows a specific type. This project uses
@element-ts/oxygen which is another package in the
element-ts family. All you need to do is specify a types
object when creating a new
endpoint. If an incoming request does not provide the required types, an error will be sent and then the socket will be
closed.
endpointGroup.get("/endpoint", {
handler: async(req: HRequest, res: HResponse): Promise<void> => {
const body: {name: string, age: number} = req.getBody();
res.sendString(`Yay ${body.name}, provided the right types!`);
},
types: {
age: OStandardType.number,
name: OStandardType.string
}
});
For more documentation view oxygen on Github.
Created by Elijah Cobb provided under the MIT license.
- Home
- Examples
- Creating an Endpoint
- Requests
- Responses
- Files
- Enforcing Types
- Endpoint Groups
- Creating a Server
- Using
HObject
- Error Handling
- Dynamic Endpoints
- Post Process Handler
Element is a group of developer tools I have built in TypeScript. Check them out at: element-ts.com.
Author: Elijah Cobb
NPM: @element-ts/hydrogen
Issue Reporting: Github Issues