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

Possible usecase: validating runtime AJAX responses #37

Open
ducin opened this issue Oct 24, 2015 · 2 comments
Open

Possible usecase: validating runtime AJAX responses #37

ducin opened this issue Oct 24, 2015 · 2 comments

Comments

@ducin
Copy link

ducin commented Oct 24, 2015

Hello all,

I thought of a possible use case of typson and thought it might be great, if it worked out, though, I wanna discuss it with you all.

Let's assume we've got an application written in TypeScript. What TypeScript itself gives us is compile-time typecheck. That is great to find bugs statically, but it can't help us to check anything on runtime. Therefore, what we can do in TS code is to typecast the dynamic response (which we will determine in future) to a static type, but, when transpiled into raw javascript, it will not have any impact nor it will add any behavior.

Now let's say we want to validate contents of a GET request. We know that the expected result should match a given TypeScript type. We use typson to generate JSON schema for that type. And one of the JSON Schema validators (there are many of them in JS only) will be used to typecheck in runtime.

As far as I understand the whole stack of tools (and as long as typson supports typescript well), this would work correctly out of the box. Guess this feature should be somehow optional, so that we can validate all API responses in the development/test environments, but not in the production (due to performance reason).

Please comment on this - what do you think of that feature?

@ariutta
Copy link

ariutta commented Oct 25, 2015

I've been thinking about this as well. Here are a few relevant discussions/ideas:

hugapi/hug#32
Mec-iS/mild-QL#3
https://gist.github.com/ariutta/109a3d8a772dc503e40f

It would be interesting to consider how this might relate to GraphQL and/or JSON-LD.

@ariutta
Copy link

ariutta commented Oct 25, 2015

A simple proof of concept could be Express middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants