News for hackers. Stuff that matters.
Re:Robust APIs Are Weird by nine_k on Saturday June 20, 2020 @12:31AM (#23581679)
To tell the truth, there is json-schema[1], and a number of implementations of it which work pretty well.

You can use it to validate your JSON inputs, much like you would with XSD (I've used both).

There is OpenAPI, née Swagger [2], which allows you to describe your API in human- and machine-readable form and generate code for it [3].

But validation is but one step. A robust API needs rate-limiting, injection protection (does your language has tainted strings?), easy enough authz/authn story, etc, etc, all different and non-trivial things.

[1]: http://json-schema.org/ [2]: https://en.wikipedia.org/wiki/OpenAPI_Specification [3]: https://openapi-generator.tech/

Re:Robust APIs Are Weird by Sherl on Saturday June 20, 2020 @12:59AM (#23581809)
The openAPI uses Python flask but to be frank, it makes sense to use the schema to generate client rather then server. FastAPI and Pydantic can generate openAPI schema from datamodel which does the type parsing for you, if parsing is the use case. Writing server code with a library that can generate schema is a pro for me rather then keeping up with updates from schema to code.