|
2 | 2 |
|
3 | 3 | > **Learn sebuf through working examples** |
4 | 4 |
|
5 | | -## 🚀 Start here: Simple API |
| 5 | +## Quick Start: Simple API |
6 | 6 |
|
7 | 7 | **Want to see sebuf in action immediately?** |
8 | 8 |
|
9 | 9 | ```bash |
10 | | -# Clone the repo and run the complete example |
11 | 10 | git clone https://github.com/SebastienMelki/sebuf.git |
12 | 11 | cd sebuf/examples/simple-api |
13 | 12 | make demo |
14 | 13 | ``` |
15 | 14 |
|
16 | | -This starts a working HTTP API with: |
17 | | -- User management and authentication |
18 | | -- Multiple auth methods (email, token, social) |
19 | | -- Type-safe request construction |
20 | | -- OpenAPI documentation |
| 15 | +This starts a working HTTP API with user management, authentication, and OpenAPI docs. |
| 16 | + |
| 17 | +**[Go to Simple API Tutorial](../../examples/simple-api/)** |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## All Examples |
| 22 | + |
| 23 | +| Example | Description | Key Features | |
| 24 | +|---------|-------------|--------------| |
| 25 | +| **[simple-api](../../examples/simple-api/)** | User authentication API | Oneof helpers, multiple auth methods, basic HTTP endpoints | |
| 26 | +| **[restful-crud](../../examples/restful-crud/)** | Product catalog API | GET, POST, PUT, PATCH, DELETE, path params, query params, pagination | |
| 27 | +| **[validation-showcase](../../examples/validation-showcase/)** | Order processing API | buf.validate patterns: string, numeric, array, map, nested validation | |
| 28 | +| **[nested-resources](../../examples/nested-resources/)** | Organization hierarchy API | Deep path nesting (3 levels), multiple path params per endpoint | |
| 29 | +| **[multi-service-api](../../examples/multi-service-api/)** | Multi-tenant platform | Multiple services, different auth levels, service/method headers | |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## Example Details |
| 34 | + |
| 35 | +### simple-api |
| 36 | +Basic introduction to sebuf with user authentication. |
| 37 | +- Oneof helpers for type-safe authentication methods |
21 | 38 | - JSON and binary protobuf support |
| 39 | +- OpenAPI documentation generation |
| 40 | + |
| 41 | +```bash |
| 42 | +cd examples/simple-api && make demo |
| 43 | +``` |
| 44 | + |
| 45 | +### restful-crud |
| 46 | +Complete RESTful CRUD operations for a product catalog. |
| 47 | +- All HTTP verbs: GET, POST, PUT, PATCH, DELETE |
| 48 | +- Path parameters: `/products/{product_id}` |
| 49 | +- Query parameters: pagination, filtering, sorting |
| 50 | +- PUT vs PATCH semantics with optional fields |
| 51 | + |
| 52 | +```bash |
| 53 | +cd examples/restful-crud && make demo |
| 54 | +``` |
| 55 | + |
| 56 | +### validation-showcase |
| 57 | +Comprehensive buf.validate validation patterns. |
| 58 | +- String: min_len, max_len, email, uuid, pattern (regex), enum |
| 59 | +- Numeric: gte, lte, gt, lt bounds |
| 60 | +- Array: min_items, max_items, unique items |
| 61 | +- Map: max_pairs, key/value validation |
| 62 | +- Nested message validation |
| 63 | + |
| 64 | +```bash |
| 65 | +cd examples/validation-showcase && make demo |
| 66 | +``` |
22 | 67 |
|
23 | | -**→ [Go to the Simple API Tutorial](../../examples/simple-api/)** |
| 68 | +### nested-resources |
| 69 | +Complex resource hierarchies with multiple path parameters. |
| 70 | +- Organization > Team > Member/Project hierarchy |
| 71 | +- Up to 3 path parameters per endpoint |
| 72 | +- GitHub-style nested resource URLs |
24 | 73 |
|
25 | | -## What the example shows |
| 74 | +```bash |
| 75 | +cd examples/nested-resources && make demo |
| 76 | +``` |
| 77 | + |
| 78 | +**Endpoints:** |
| 79 | +``` |
| 80 | +GET /api/v1/orgs/{org_id}/teams/{team_id}/members/{member_id} |
| 81 | +POST /api/v1/orgs/{org_id}/teams/{team_id}/projects |
| 82 | +``` |
| 83 | + |
| 84 | +### multi-service-api |
| 85 | +Multiple services with different authentication requirements. |
| 86 | +- **PublicService** - No auth required (health, info) |
| 87 | +- **UserService** - User auth (Authorization + X-Tenant-ID) |
| 88 | +- **AdminService** - Admin auth with method-specific headers |
| 89 | + |
| 90 | +```bash |
| 91 | +cd examples/multi-service-api && make demo |
| 92 | +``` |
| 93 | + |
| 94 | +**Header patterns:** |
| 95 | +- Service-level headers applied to all methods |
| 96 | +- Method-level headers for specific operations (X-Confirm-Delete, X-Audit-Reason) |
26 | 97 |
|
27 | | -✅ **HTTP handlers** from protobuf services |
28 | | -✅ **Oneof helpers** that eliminate boilerplate |
29 | | -✅ **OpenAPI docs** that stay in sync |
30 | | -✅ **Multiple content types** (JSON + binary protobuf) |
31 | | -✅ **Real authentication patterns** |
| 98 | +--- |
| 99 | + |
| 100 | +## Running Examples |
| 101 | + |
| 102 | +Each example follows the same pattern: |
| 103 | + |
| 104 | +```bash |
| 105 | +# Run complete demo (generate + run) |
| 106 | +make demo |
| 107 | + |
| 108 | +# Individual steps |
| 109 | +make generate # Generate code from proto |
| 110 | +make run # Start the server |
| 111 | +make test # Test with curl commands |
| 112 | +make clean # Remove generated files |
| 113 | +``` |
32 | 114 |
|
33 | | -## More examples (coming soon) |
| 115 | +## What Each Example Demonstrates |
34 | 116 |
|
35 | | -- **E-commerce API** - Product catalog, cart, checkout |
36 | | -- **Chat API** - Real-time messaging with websockets |
37 | | -- **File Upload API** - Handle binary data and metadata |
38 | | -- **Microservices** - Inter-service communication patterns |
| 117 | +| Feature | simple-api | restful-crud | validation | nested | multi-service | |
| 118 | +|---------|:----------:|:------------:|:----------:|:------:|:-------------:| |
| 119 | +| HTTP verbs (GET/POST) | Yes | Yes | Yes | Yes | Yes | |
| 120 | +| PUT/PATCH/DELETE | - | Yes | - | Yes | Yes | |
| 121 | +| Path parameters | - | Yes | - | Yes | Yes | |
| 122 | +| Query parameters | - | Yes | - | Yes | - | |
| 123 | +| buf.validate | Basic | Basic | Comprehensive | Basic | Basic | |
| 124 | +| Header validation | - | Yes | - | - | Yes | |
| 125 | +| Multiple services | - | - | - | - | Yes | |
| 126 | +| Nested resources | - | - | - | Yes | - | |
| 127 | +| Oneof helpers | Yes | - | - | - | - | |
| 128 | + |
| 129 | +--- |
39 | 130 |
|
40 | 131 | ## Want to contribute an example? |
41 | 132 |
|
42 | | -We're looking for real-world examples that show sebuf solving actual problems. See [Contributing Guidelines](../../CONTRIBUTING.md). |
| 133 | +We welcome real-world examples that show sebuf solving actual problems. See [Contributing Guidelines](../../CONTRIBUTING.md). |
43 | 134 |
|
44 | 135 | --- |
45 | 136 |
|
46 | | -**Start with the [Simple API Tutorial](../../examples/simple-api/) →** |
| 137 | +**Start with the [Simple API Tutorial](../../examples/simple-api/)** |
0 commit comments