Skip to content

Commit 44dbe63

Browse files
committed
polish Vix guides tables
1 parent 2afd6e5 commit 44dbe63

12 files changed

Lines changed: 148 additions & 121 deletions

guides/authentication.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ You will build:
1010
- protected routes
1111
- bearer token style authentication
1212

13-
> This guide keeps the implementation simple and in-memory. For production, store users in SQLite or MySQL, hash passwords, and use real JWT/session middleware.
13+
> This guide keeps the implementation simple and in-memory.
14+
For production, store users in SQLite or MySQL, hash passwords, and use real JWT/session middleware.
1415

1516
## Goal
1617

@@ -199,13 +200,13 @@ curl -i http://127.0.0.1:8080/private
199200

200201
## Authentication status codes
201202

202-
| Status | Meaning | Example |
203-
|--------|---------|---------|
204-
| 201 | Created | User registered |
205-
| 400 | Bad Request | Invalid input |
206-
| 401 | Unauthorized | Missing or invalid token |
207-
| 403 | Forbidden | Authenticated but not allowed |
208-
| 409 | Conflict | Email already registered |
203+
| Status | Meaning | Example |
204+
|--------|---------------|-----------------------------------|
205+
| `201` | Created. | User registered successfully. |
206+
| `400` | Bad Request. | Invalid input was provided. |
207+
| `401` | Unauthorized. | Missing or invalid auth token. |
208+
| `403` | Forbidden. | User is authenticated but denied. |
209+
| `409` | Conflict. | Email is already registered. |
209210

210211
## Important production notes
211212

guides/build-rest-api.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ curl -i http://127.0.0.1:8080/
5050

5151
## Basic Vix HTTP structure
5252

53-
| Part | Purpose |
54-
|------|---------|
55-
| `App app;` | Creates the HTTP application |
56-
| `app.get(...)` | Registers a GET route |
57-
| `Request &req` | Gives access to request data |
58-
| `Response &res` | Sends the response |
59-
| `res.json(...)` | Sends JSON |
60-
| `app.run(8080)` | Starts the server on port 8080 |
53+
| Part | Purpose |
54+
|------------------|------------------------------------------|
55+
| `App app;` | Creates the HTTP application instance. |
56+
| `app.get(...)` | Registers a `GET` route handler. |
57+
| `Request &req` | Provides access to request data. |
58+
| `Response &res` | Provides methods for sending responses. |
59+
| `res.json(...)` | Sends a JSON response. |
60+
| `app.run(8080)` | Starts the server on port `8080`. |
6161

6262
## Create a health route
6363

@@ -140,15 +140,15 @@ app.get("/users", [&users](Request &req, Response &res){
140140

141141
Useful request APIs:
142142

143-
| API | Purpose |
144-
|-----|---------|
145-
| `req.param("id")` | Read path param |
146-
| `req.param("id", "0")` | Read path param with fallback |
147-
| `req.query_value("page", "1")` | Read query param with fallback |
148-
| `req.query()` | Read all query params |
149-
| `req.body()` | Read raw body |
150-
| `req.json()` | Read parsed JSON body |
151-
| `req.header("Authorization")` | Read request header |
143+
| API | Purpose |
144+
|----------------------------------|------------------------------------------|
145+
| `req.param("id")` | Reads a route path parameter. |
146+
| `req.param("id", "0")` | Reads a route parameter with fallback. |
147+
| `req.query_value("page", "1")` | Reads a query parameter with fallback. |
148+
| `req.query()` | Reads all query parameters. |
149+
| `req.body()` | Reads the raw request body. |
150+
| `req.json()` | Reads the parsed JSON body. |
151+
| `req.header("Authorization")` | Reads a request header value. |
152152

153153
## Add POST /users
154154

@@ -370,15 +370,15 @@ res.file("public/index.html"); // File
370370
371371
## Status codes
372372
373-
| Status | Meaning | Example |
374-
|--------|---------|---------|
375-
| 200 | OK | Successful GET |
376-
| 201 | Created | Successful POST |
377-
| 400 | Bad Request | Invalid input |
378-
| 401 | Unauthorized | Missing auth |
379-
| 403 | Forbidden | Not allowed |
380-
| 404 | Not Found | Missing resource |
381-
| 500 | Internal Server Error | Server failure |
373+
| Status | Meaning | Example |
374+
|--------|-------------------------|---------------------------------|
375+
| `200` | OK. | Successful `GET` request. |
376+
| `201` | Created. | Successful `POST` request. |
377+
| `400` | Bad Request. | Invalid input was provided. |
378+
| `401` | Unauthorized. | Authentication is missing. |
379+
| `403` | Forbidden. | Access is not allowed. |
380+
| `404` | Not Found. | Requested resource is missing. |
381+
| `500` | Internal Server Error. | Server-side failure occurred. |
382382
383383
## Recommended JSON shape
384384
@@ -422,7 +422,9 @@ vix run main.cpp -- --port 8080 # wrong: -- is for compiler flags
422422

423423
### Expecting in-memory data to persist
424424

425-
The `users` vector is in memory. If the server restarts, created users are lost. For persistence, use SQLite or MySQL.
425+
The `users` vector is in memory.
426+
If the server restarts, created users are lost.
427+
For persistence, use SQLite or MySQL.
426428

427429
## What to use next
428430

guides/cors.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ API: http://localhost:8080
1111

1212
## What is CORS?
1313

14-
An origin is composed of scheme + host + port. The browser uses CORS to decide whether frontend JavaScript is allowed to call an API on another origin.
14+
An origin is composed of scheme + host + port.
15+
The browser uses CORS to decide whether frontend JavaScript is allowed to call an API on another origin.
1516

1617
## Setup
1718

@@ -98,13 +99,13 @@ curl -i -X OPTIONS http://127.0.0.1:8080/api/messages \
9899

99100
## CORS headers explained
100101

101-
| Header | Purpose |
102-
|--------|---------|
103-
| `Access-Control-Allow-Origin` | Which origin is allowed |
104-
| `Access-Control-Allow-Methods` | Which methods are allowed |
105-
| `Access-Control-Allow-Headers` | Which request headers are allowed |
106-
| `Access-Control-Allow-Credentials` | Whether credentials are allowed |
107-
| `Access-Control-Expose-Headers` | Which response headers JS can read |
102+
| Header | Purpose |
103+
|------------------------------------|----------------------------------------------|
104+
| `Access-Control-Allow-Origin` | Defines which origin is allowed. |
105+
| `Access-Control-Allow-Methods` | Defines which HTTP methods are allowed. |
106+
| `Access-Control-Allow-Headers` | Defines which request headers are allowed. |
107+
| `Access-Control-Allow-Credentials` | Defines whether credentials are allowed. |
108+
| `Access-Control-Expose-Headers` | Defines which response headers JS can read. |
108109

109110
## Common mistakes
110111

guides/mysql-api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ curl -i -X POST http://127.0.0.1:8080/users \
105105

106106
## SQLite vs MySQL
107107

108-
| Feature | SQLite | MySQL |
109-
|---------|--------|-------|
110-
| Deployment | Local file | Server database |
111-
| Setup | Very simple | Requires server |
112-
| Best for | local apps, small APIs | multi-user production APIs |
108+
| Feature | SQLite | MySQL |
109+
|-------------|------------------------------------|-----------------------------------|
110+
| Deployment | Stores data in a local file. | Stores data in a server database. |
111+
| Setup | Very simple, no server required. | Requires a database server. |
112+
| Best for | Local apps, small APIs, and MVPs. | Multi-user production APIs. |
113113

114114
## Common mistakes
115115

guides/production-nginx-systemd.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ curl -i https://example.com/health
202202

203203
### 502 Bad Gateway
204204

205-
App is not running. Check: `sudo systemctl status vix-myapp` and `curl -i http://127.0.0.1:8080/health`.
205+
App is not running.
206+
Check: `sudo systemctl status vix-myapp` and `curl -i http://127.0.0.1:8080/health`.
206207

207208
### 504 Gateway Timeout
208209

guides/rate-limiting.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ app.use(vix::middleware::app::adapt_ctx(
6060

6161
## Where to apply rate limiting
6262

63-
| Endpoint | Suggested limit |
64-
|----------|----------------|
65-
| `GET /health` | high or no limit |
66-
| `GET /api/*` | normal limit |
67-
| `POST /auth/login` | strict limit |
68-
| `POST /auth/register` | strict limit |
69-
| `POST /password/reset` | very strict limit |
63+
| Endpoint | Suggested limit |
64+
|--------------------------|------------------------------|
65+
| `GET /health` | High limit or no limit. |
66+
| `GET /api/*` | Normal application limit. |
67+
| `POST /auth/login` | Strict authentication limit. |
68+
| `POST /auth/register` | Strict registration limit. |
69+
| `POST /password/reset` | Very strict recovery limit. |
7070

7171
## Test rate limiting
7272

guides/sessions.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Sessions are useful for: login state, dashboards, admin panels, browser-based au
1212

1313
## Session vs token authentication
1414

15-
| Style | Common use |
16-
|-------|-----------|
17-
| Bearer token | APIs, mobile apps, service-to-service |
18-
| Session cookie | Browser apps, dashboards, server-rendered apps |
15+
| Style | Common use |
16+
|----------------|----------------------------------------------------|
17+
| Bearer token | APIs, mobile apps, and service-to-service calls. |
18+
| Session cookie | Browser apps, dashboards, and server-rendered apps.|
1919

2020
## Setup
2121

@@ -148,12 +148,12 @@ const std::string session_id = *value;
148148

149149
## Session status codes
150150

151-
| Status | Meaning |
152-
|--------|---------|
153-
| 200 | Session exists or request succeeded |
154-
| 400 | Invalid login body |
155-
| 401 | Missing or invalid session |
156-
| 403 | Session exists but user is not allowed |
151+
| Status | Meaning |
152+
|--------|----------------------------------------------|
153+
| `200` | Session exists or request succeeded. |
154+
| `400` | Login request body is invalid. |
155+
| `401` | Session is missing, expired, or invalid. |
156+
| `403` | Session exists, but access is not allowed. |
157157

158158
## Production notes
159159

guides/sqlite-api.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ curl -i -X POST http://127.0.0.1:8080/users \
127127

128128
## Common SQLite types
129129

130-
| SQLite type | Use for |
131-
|------------|---------|
132-
| `INTEGER` | ids, counters, timestamps |
133-
| `TEXT` | strings, emails, names |
134-
| `REAL` | floating-point values |
135-
| `BLOB` | binary data |
130+
| SQLite type | Use for |
131+
|-------------|----------------------------------|
132+
| `INTEGER` | IDs, counters, and timestamps. |
133+
| `TEXT` | Strings, emails, and names. |
134+
| `REAL` | Floating-point numeric values. |
135+
| `BLOB` | Binary data. |
136136

137137
## Common mistakes
138138

guides/static-files.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ app.get("/*", [](Request &req, Response &res){
7878

7979
## Cache headers
8080

81-
| Header value | Meaning |
82-
|-------------|---------|
83-
| `no-store` | Do not cache |
84-
| `no-cache` | Revalidate before reuse |
85-
| `public, max-age=3600` | Cache for 1 hour |
86-
| `public, max-age=86400` | Cache for 1 day |
87-
| `public, max-age=31536000, immutable` | Cache versioned assets for 1 year |
81+
| Header value | Meaning |
82+
|-----------------------------------------|----------------------------------------------|
83+
| `no-store` | Does not store the response in any cache. |
84+
| `no-cache` | Revalidates the response before reuse. |
85+
| `public, max-age=3600` | Caches the response for one hour. |
86+
| `public, max-age=86400` | Caches the response for one day. |
87+
| `public, max-age=31536000, immutable` | Caches versioned assets for one year. |
8888

8989
## Advanced static files middleware
9090

guides/templates.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ app.templates("./views");
4141
```html
4242
<!doctype html>
4343
<html lang="en">
44-
<head><meta charset="utf-8" /><title>{{ title }}</title></head>
44+
<head>
45+
<meta charset="utf-8" />
46+
<title>{{ title }}</title>
47+
</head>
4548
<body>
4649
<h1>{{ title }}</h1>
4750
<p>Hello {{ user }}.</p>
@@ -105,8 +108,15 @@ ctx.set("features", features);
105108
```html
106109
<!doctype html>
107110
<html lang="en">
108-
<head><meta charset="utf-8" /><title>{{ title }}</title></head>
109-
<body><main>{% block content %}{% endblock %}</main></body>
111+
<head>
112+
<meta charset="utf-8" />
113+
<title>{{ title }}</title>
114+
</head>
115+
<body>
116+
<main>
117+
{% block content %}{% endblock %}
118+
</main>
119+
</body>
110120
</html>
111121
```
112122

@@ -127,7 +137,10 @@ ctx.set("features", features);
127137
```html
128138
<header>
129139
<strong>{{ app_name }}</strong>
130-
<nav><a href="/">Home</a> <a href="/dashboard">Dashboard</a></nav>
140+
<nav>
141+
<a href="/">Home</a>
142+
<a href="/dashboard">Dashboard</a>
143+
</nav>
131144
</header>
132145
```
133146

@@ -180,14 +193,14 @@ ctx.set("recent_orders", orders);
180193

181194
## Template features
182195

183-
| Feature | Example |
184-
|---------|---------|
185-
| Variable | `{{ title }}` |
186-
| Condition | `{% if logged_in %}` |
187-
| Loop | `{% for item in items %}` |
188-
| Include | `{% include "header.html" %}` |
189-
| Layout | `{% extends "base.html" %}` |
190-
| Block | `{% block content %}` |
196+
| Feature | Example |
197+
|------------|---------------------------------|
198+
| Variable | `{{ title }}` |
199+
| Condition | `{% if logged_in %}` |
200+
| Loop | `{% for item in items %}` |
201+
| Include | `{% include "header.html" %}` |
202+
| Layout | `{% extends "base.html" %}` |
203+
| Block | `{% block content %}` |
191204

192205
## Templates with database data
193206

@@ -231,7 +244,8 @@ app.templates("./views"); // required before res.render(...)
231244

232245
### Putting all logic in the template
233246

234-
Keep calculations and database queries in C++. Pass simple, ready-to-render values to the template.
247+
Keep calculations and database queries in C++.
248+
Pass simple, ready-to-render values to the template.
235249

236250
### Forgetting layout variables
237251

0 commit comments

Comments
 (0)