cal.pub0.org/README.md

44 lines
1.7 KiB
Markdown
Raw Normal View History

2022-03-18 13:42:42 +00:00
# Cal.com Public API (Enterprise Only)
2022-03-23 21:22:57 +00:00
## This will be the new public enterprise-only API
2022-03-25 05:54:57 +00:00
This is the public REST api for cal.com
2022-03-23 21:22:57 +00:00
## NextJS + TypeScript
It's a barebones **NextJS** + **TypeScript** project leveraging the nextJS API with a pages/api folder.
## No react
It doesn't have react or react-dom as a dependency, and will only be used by a redirect as a folder or subdomain on cal.com with maybe a v1 tag like:
- `api.cal.com/v1`
2022-03-25 05:54:57 +00:00
- `api.cal.com/api/v1`
2022-03-23 21:22:57 +00:00
2022-03-25 05:54:57 +00:00
## API Endpoint Validation
2022-03-23 21:22:57 +00:00
2022-03-25 05:54:57 +00:00
### Zod
2022-03-23 21:22:57 +00:00
The API uses `zod` library like our main web repo. It validates that either GET query parameters or POST body content's are valid and up to our spec. It gives appropiate errors when parsing result's with schemas.
2022-03-25 05:54:57 +00:00
### Next Validations
[Next-Validations Docs](https://next-validations.productsway.com/)
[Next-Validations Repo](https://github.com/jellydn/next-validations)
We also use this useful helper library that let's us wrap our endpoints in a validate HOC that checks the req against our validation schema built out with zod for either query and / or body's requests.
2022-03-23 21:32:46 +00:00
## Testing with Jest + node-mocks-http
2022-03-25 05:54:57 +00:00
We aim to provide a fully tested API for our peace of mind, this is accomplished by using jest + node-mocks-http
## Next.config.js
### Redirects
Since this will only support an API, we redirect the requests to root to the /api folder.
We also added a redirect for future-proofing API versioning when we might need it, without having to resort to dirty hacks like a v1/v2 folders with lots of duplicated code, instead we redirect /api/v*/:rest to /api/:rest?version=*
The priority is the booking-related API routes so people can build their own booking flow, then event type management routes, then availability management routes etc