Example Applications
The Shokupan repository includes sample applications that demonstrate real-world usage patterns. These are tested against every release.
Sample Applications
Section titled “Sample Applications”1. Basic REST API
Section titled “1. Basic REST API”A Todo API using functional routing, middleware, and CRUD patterns.
cd samples/01-basic-rest-apibun run devFeatures:
- Functional routing (
app.get,app.post,app.put,app.delete) - Request logging middleware
- Path and query parameters
- JSON request/response handling
Endpoints:
GET /health— Health checkGET /todos— List todosGET /todos/:id— Get single todoPOST /todos— Create todoPUT /todos/:id— Update todoDELETE /todos/:id— Delete todo
2. Decorator Controllers
Section titled “2. Decorator Controllers”A User API using decorator-based controllers and dependency injection.
cd samples/02-decorator-controllersbun run devFeatures:
@Controller,@Get,@Postdecorators@Param,@Bodyparameter binding@Injectableservices with constructor injectionContainerfor DI management
Endpoints:
GET /api/users— List usersGET /api/users/:id— Get user by IDPOST /api/users— Create user
3. WebSocket Real-time App
Section titled “3. WebSocket Real-time App”A chat application using ShokupanWebsocketRouter.
cd samples/03-websocket-realtimebun run devFeatures:
- Event-based WebSocket handling
- Named events with typed payloads
- Message history (in-memory)
- AsyncAPI generation
Events:
chat.join— Welcome messagechat.message— Send/receive messageschat.history— Request message historyping/pong— Keep-alive
4. Fullstack Vite Integration
Section titled “4. Fullstack Vite Integration”A backend API with Vite frontend integration.
cd samples/04-fullstack-vitebun run devFeatures:
- Shokupan API backend
VitePluginfor dev server integration- SPA fallback support
- Single-port fullstack development
Endpoints:
GET /api/health— Health checkGET /api/items— List itemsGET /api/items/:id— Get item by ID
5. Auth + Validation
Section titled “5. Auth + Validation”A protected blog API with Zod validation and session-based auth.
cd samples/05-auth-validationbun run devFeatures:
validate()middleware with Zod schemasSession()middleware for stateful auth- Role-based route protection
- Public vs protected endpoints
Test Credentials:
admin/admin123(admin role)alice/alice123(user role)
6. File Upload
Section titled “6. File Upload”Multipart form upload handling with file streaming and download.
cd samples/06-file-uploadbun run devFeatures:
- Multipart form data upload
- File listing and download
- File streaming for large files
Endpoints:
POST /upload— Upload filesGET /files— List uploaded filesGET /files/:name— Download a fileGET /stream/:name— Stream a file
7. GraphQL API
Section titled “7. GraphQL API”GraphQL server using the GraphQL Yoga plugin.
cd samples/07-graphql-apibun run devFeatures:
- GraphQL schema with queries and mutations
- GraphQL Yoga plugin integration
- In-memory data store
Endpoints:
POST /graphql— GraphQL endpoint
8. Server-Sent Events
Section titled “8. Server-Sent Events”Real-time event streaming with SSE.
cd samples/08-server-sent-eventsbun run devFeatures:
- SSE stream with
ctx.streamSSE() - Automatic event ID tracking
- JSON event history endpoint
Endpoints:
GET /events— SSE streamGET /events/history— Recent eventsPOST /events— Create manual event
9. HTMX Fullstack
Section titled “9. HTMX Fullstack”Server-rendered interactive app with HTMX partial updates.
cd samples/09-htmx-fullstackbun run devFeatures:
- Server-side HTML rendering
- HTMX attributes for interactivity
- Todo CRUD without client-side JavaScript
Endpoints:
GET /— Full HTML pageGET /todos/partial— Todo list partialPOST /todos— Create todoPOST /todos/:id/toggle— Toggle completionDELETE /todos/:id— Delete todo
10. Microservices
Section titled “10. Microservices”Multiple services with internal sub-requests via internalRequest().
cd samples/10-microservicesbun run devFeatures:
- Multiple Shokupan services
- Internal HTTP sub-requests
- Gateway aggregation pattern
Services:
- User Service —
http://localhost:3010 - Order Service —
http://localhost:3011 - Gateway —
http://localhost:3012
Running Tests
Section titled “Running Tests”Each sample includes tests that verify it compiles and the core imports work:
cd samples/01-basic-rest-apibun testUsing Samples as Templates
Section titled “Using Samples as Templates”Each sample is a self-contained Bun project. To use one as a starting point:
cp -r samples/01-basic-rest-api my-projectcd my-project# Update package.json dependencies from 'link:shokupan' to '^1.0.0'bun installNext Steps
Section titled “Next Steps”- Quick Start — Build your first Shokupan app
- Routing — Learn routing patterns
- Controllers — Use decorator-based controllers