Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ethan-arrowood/openjs-world-2021
My Fastify/Undici/TypeScript talk for OpenJS World 2021
https://github.com/ethan-arrowood/openjs-world-2021
Last synced: 9 days ago
JSON representation
My Fastify/Undici/TypeScript talk for OpenJS World 2021
- Host: GitHub
- URL: https://github.com/ethan-arrowood/openjs-world-2021
- Owner: Ethan-Arrowood
- Created: 2021-05-17T17:05:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-18T20:53:41.000Z (over 3 years ago)
- Last Synced: 2024-10-05T17:42:45.372Z (3 months ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Safely Handling Dynamic Data with TypeScript
Featuring [Fastify](https://www.fastify.io/), [Undici](https://undici.nodejs.org/), [TypeBox](https://github.com/sinclairzx81/typebox), and [AJV](https://ajv.js.org/) 🚀
This repository contains an example of safely handling dynamic data using TypeScript within a full stack web application. The Fastify server and the Undici client share a set of JSON schemas and relative TypeScript type definitions. These schemas and type definitions are used in different ways by the server and client, but achieve the same effect; the incoming and outgoing data can be validated and assigned a type **safely** with only a few extra lines of code.
Most applications should already be validating data. This is not only a security concern, but also helps prevent unnecessary crashes when the expected data is incorrect. In TypeScript its common to find this kind of data used unsafely since correctly assigning the data object a type based on the validation is difficult. By combining tools such as TypeBox and AJV, both applications can be assured the data is what the developer expects it to be.
## Running the Demo
1. Clone repo and install dependencies (`npm i`)
2. Build the TypeScript code (`npm run build`)
3. Launch the Fastify server (`npm run start:server`)
4. Launch the Undici client script (`npm run start:client`)