Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Allow defining an endpoint with client-side response validation #3

Open
Schniz opened this issue Jun 30, 2022 · 1 comment
Open

Allow defining an endpoint with client-side response validation #3

Schniz opened this issue Jun 30, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Schniz
Copy link
Collaborator

Schniz commented Jun 30, 2022

The idea behind this feature is to enable long-running clients to react to changes in the backend schemas. Imagine you have an endpoint that returns { version: 1, data: string } and then while the customer is on your app, the server redeploys and now it returns { version: 2, result: string }. You probably want to make a hard-refresh, or at least show an error.

The suggested API would be something like:

import { query } from 'next-swr-endpoints';
export const useNoClientTypecheck = query(myParser, (value) => ...)
export const useWithClientTypecheck = query({ input: myParser, output: anotherParser }, value => ...)
@Schniz Schniz added the enhancement New feature or request label Jun 30, 2022
@Schniz
Copy link
Collaborator Author

Schniz commented Aug 11, 2022

This can also be handy for stuff like passing Date objects, if the parser is symmetric (Parser<From, To> = { parse(from: From): To, encode(to: To): From }), but Zod unfortunately does not support that syntax AFAIK (while io-ts does)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant