Superstruct
Backend / API library · Free
A JavaScript and TypeScript runtime validation library: it defines data structures and validates application API boundaries.
Also known as: ianstormtaylor/superstruct; superstruct; data-validation-js; superstruct-validation
What you can use for free
Code and local use under MIT.
Paid features and costs
Computing resources, self-hosting, and external services are paid for separately if used.
Access and limitations
Code and local use under MIT. Computing resources, self-hosting, and external services are paid for separately if used.
Use cases
- Validate input structure at runtime
- Add validation at an API boundary and test acceptance and rejection of examples
Example workflow
A possible workflow; this is not a report of hands-on testing.
Validate input structure at runtime.
Before you start
- A data contract or HTTP workflow.
- A project with a supported runtime.
Steps
- Define a schema for external data entering the application.
- Add validation at an API boundary and test acceptance and rejection of examples.
- Add error handling and an integration check of the result.
Check your result
- Invalid and missing data are handled predictably.
- Types and the actual response agree; errors are not hidden.
Choosing Superstruct
Validate input structure at runtime
Choose this when
- Validate input structure at runtime
- Add validation at an API boundary and test acceptance and rejection of examples
Requirements
- Define structs and decide where coercion is acceptable and where input must be strictly rejected.
Things to consider
- Costs and limits of free use: Computing resources, self-hosting, and external services are paid for separately if used.
- Terms of use: MIT for the code; dependencies have separate licenses.
- A TypeScript type alone does not validate external JSON. Custom email/UUID rule correctness depends on the chosen validator.
Frequently asked questions
What can you use for free in Superstruct?
Code and local use under MIT.
What additional costs might arise with Superstruct?
Computing resources, self-hosting, and external services are paid for separately if used.
What terms of use matter for Superstruct?
MIT for the code; dependencies have separate licenses.
How do you get started with Superstruct?
Define a schema for external data entering the application. Add validation at an API boundary and test acceptance and rejection of examples. Add error handling and an integration check of the result.
How do assert, is, validate, and create differ in Superstruct?
A Struct defines data shape for runtime validation. assert throws on mismatch; is and validate check without that throw. create applies coercion/default values during validation. Custom validators are defined separately, and TypeScript can narrow data types after successful validation.
License
MIT for the code; dependencies have separate licenses.
MIT — permissive license
You can use, modify, distribute, and sell the code, including in a closed-source commercial product. When sharing copies or substantial portions of the code, retain the license text and copyright notice. You do not need to open-source your entire project; the author provides no warranties.
License termsTechnologies and topics
- Superstruct
- API
- Development