Skip to content
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.

Example

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.

Pages

element-ts

Element is a group of developer tools I have built in TypeScript. Check them out at: element-ts.com.

About

Author: Elijah Cobb

NPM: @element-ts/hydrogen

Issue Reporting: Github Issues

Clone this wiki locally