@legible-sync/example-express
v1.3.1
Published
Express.js REST API example using LegibleSync framework
Maintainers
Readme
@legible-sync/example-express
Express.js REST API example demonstrating the LegibleSync framework in a web application.
Running the Example
From the root of the monorepo, run:
npm run dev:expressThe API will be available at http://localhost:3000
API Endpoints
Authentication
POST /users # Register new user
POST /login # User loginArticles
POST /articles # Create article
POST /articles/:id/favorite # Favorite article
DELETE /articles/:id/favorite # Unfavorite article
POST /articles/:id/comments # Add commentAuditing
GET /audit/:flowId # Get flow audit trailExample Usage
Register User
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{
"username": "alice",
"email": "[email protected]",
"password": "secure123"
}'Create Article
curl -X POST http://localhost:3000/articles \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"title": "My Article",
"body": "Article content here..."
}'Audit Flow
curl http://localhost:3000/audit/user-registration-flowFeatures Demonstrated
- REST API Integration: HTTP request/response handling
- Authentication: JWT-based auth with bcrypt passwords
- CRUD Operations: Full create/read/update/delete flows
- Social Features: Favorites and comments system
- Flow Auditing: Complete execution traceability
- Error Handling: Proper HTTP status codes and messages
Code Structure
src/
├── concepts/ # Business logic modules
│ ├── User.ts # User management
│ ├── Article.ts # Article handling
│ ├── Comment.ts # Comments system
│ ├── Favorite.ts # Favorites functionality
│ ├── Password.ts # Password validation
│ ├── JWT.ts # JWT tokens
│ └── Web.ts # HTTP abstraction
├── syncs/ # Synchronization rules
│ ├── registration.sync.ts
│ ├── article.sync.ts
│ ├── favorite.sync.ts
│ └── comment.sync.ts
├── utils/ # Utilities
│ └── audit.ts # Flow auditing
└── server.ts # Express serverLearning Points
- Building REST APIs with LegibleSync
- Authentication and authorization patterns
- Social features implementation
- HTTP request/response handling
- API design with concepts and syncs
Related Packages
- @legible-sync/core - Framework core
- @legible-sync/example-console - Console example
License
MIT License - Copyright (c) 2025 Mauro Stepanoski
