Type-Safe Fetch with Next.js, Strapi, and OpenAPI
This blog post discusses how to achieve type safety in a front-end application used for a Strapi backend. It explains that TypeScript can help when interacting with external services using their APIs, such as GraphQL and tRPC. The most commonly used APIs are still simple JSON APIs (often called REST APIs). The OpenAPI specification is introduced as a tool to describe REST APIs. The post then demonstrates how to generate TypeScript type definitions from the OpenAPI specifications using the openapi-typescript library and use them in React components. It also covers how to fetch data on both server and client sides while maintaining type safety with libraries like openapi-fetch and react-query.
Company
Strapi
Date published
April 1, 2024
Author(s)
Manuel Schoebel
Word count
2686
Hacker News points
None found.
Language
English