Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up type safe client server communication #201

Merged
merged 8 commits into from
Nov 11, 2023

Conversation

raix
Copy link
Contributor

@raix raix commented Nov 9, 2023

Summary & Motivation

We want the front-end development environment to use modern React APIs, adding the accessibility and styling ergonomics while keeping type safety when calling the API.

Accessibility can be difficult to add if it's an afterthought. The React Aria Components are based on solid ground and years of hard work and effort to create the best in class components.

Forms in React have always been hard, often involving a ton of libraries - we decided to go for the latest React APIs useFormState as it brings simplicity and readability. The code should feel familiar to developers using the latest React APIs in NextJS.

Zod is one of the best schema validation libraries out there, providing common validations and the ability to validate and parse complex and even nested structures. Infer allows developers to infer the TypeScript type from a Zod Schema.

OpenAPI-fetch is an ultra-slim and performant wrapper for fetch, enabling type-safe usage of API endpoints. Use Swashbuckle CLI to generate a swagger.json when building the WebApi, and use openapi-typescript CLI to generate a TypeScript definition file that can be used for the fetch API.

  • Add WebApp.esproj file enabling web development in Rider and Visual Studio. .esproj is the new project config and will be replacing .njsproj files
  • Set up build of Api typings, creating a generated typings file to be used by the API client
  • Configure openapi-fetch to call the Api
  • Configure React to enable useFormState APIs. This API is part of NextJS v14 server actions and an official to be React API for handling form data
  • Create an example using the latest React Aria Components form validation support. This greatly simplifies browser, client and server validation in forms and plays nicely with useFormState and zod
  • Configure CORS support in the API for development mode for now (Planning to set up a reverse proxy)

Finally, update the GitHub workflow to install Bun and node modules, and ensure that the WebApi can generate the TypeScript type definition in the GitHub runner.

Checklist

  • I have added a Label to the pull-request
  • I have added tests, and done manual regression tests
  • I have updated the documentation, if necessary

@raix raix added the Enhancement New feature or request label Nov 9, 2023
@raix raix self-assigned this Nov 9, 2023
@raix raix linked an issue Nov 9, 2023 that may be closed by this pull request
.config/dotnet-tools.json Outdated Show resolved Hide resolved
application/PlatformPlatform.sln Outdated Show resolved Hide resolved
@tjementum tjementum force-pushed the raix/setup-typesafe-client-server-communication branch 10 times, most recently from 3e8a950 to 90f6e56 Compare November 10, 2023 17:19
@raix raix force-pushed the raix/setup-typesafe-client-server-communication branch from 90f6e56 to b3e9ce0 Compare November 10, 2023 21:50
@tjementum tjementum force-pushed the raix/setup-typesafe-client-server-communication branch from b3e9ce0 to c86644d Compare November 11, 2023 00:03
@tjementum tjementum changed the title Setup typesafe client server communication Setup type safe client server communication Nov 11, 2023
@tjementum tjementum changed the title Setup type safe client server communication Set up type safe client server communication Nov 11, 2023
tjementum
tjementum previously approved these changes Nov 11, 2023
@tjementum tjementum force-pushed the raix/setup-typesafe-client-server-communication branch 8 times, most recently from ab274f0 to de641f7 Compare November 11, 2023 02:11
@tjementum tjementum force-pushed the raix/setup-typesafe-client-server-communication branch from de641f7 to 6d25b18 Compare November 11, 2023 02:30
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.21) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@tjementum tjementum merged commit 4e3b61b into main Nov 11, 2023
7 checks passed
@tjementum tjementum deleted the raix/setup-typesafe-client-server-communication branch November 11, 2023 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set up type safe client server communication
2 participants