Overview
How the “API” application works in SuperStarter.
api
application runs on port 3002. We recommend deploying it to api.{yourdomain}.com
.SuperStarter exports the API from the apps/api
directory. It is designed to be run separately from the main app, and is used to run isolate functions that are not part of the main user-facing application e.g. webhooks, cron jobs, etc.
Overview
The API is designed to run serverless functions, and is not intended to be used as a traditional Node.js server. However, it is designed to be as flexible as possible, and you can switch to running a traditional server if you need to.
Functionally speaking, splitting the API from the main app doesn’t matter if you’re running these projects on Vercel. Serverless functions are all independent pieces of infrastructure and can scale independently. However, having it run independently provides a dedicated endpoint for non-web applications e.g. mobile apps, smart home devices, etc.
Hono
SuperStarter is designed to be a scalable and production-ready fullstack starter kit. One of the core features is a dedicated and extendable API layer. To enable this in a type-safe manner, we chose Hono as the API server and their RPC client
Why Hono
Hono is a modern and minimalistic web framework for TypeScript and JavaScript. It is designed to be simple, fast and easy to use. It is also designed to be very flexible and easy to extend. You can deploy it almost anywhere and use it in a type-safe manner with the Hono RPC client. It is also capable of generating an OpenAPI documenation automatically for you API.
Don’t worry, if you don’t plan to use Hono for the time being, you can continue to use Next.js API Routing to handle API requests. You can skip the later chapters, and Hono is just an optional alternative, it is not a must.
Features
- Cron jobs: The API is used to run cron jobs. These are defined in the
apps/api/app/cron
directory. Each cron job is a.ts
file that exports a route handler. - Webhooks: The API is used to run inbound webhooks. These are defined in the
apps/api/app/webhooks
directory. Each webhook is a.ts
file that exports a route handler.
Development
To start the app, run the following command in the root directory: