@tsonic/express 10.0.1 → 10.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,59 +1,129 @@
1
1
  # @tsonic/express
2
2
 
3
- `@tsonic/express` is the generated TypeScript package for the `express-clr` runtime.
3
+ Express-style HTTP server APIs for **Tsonic** (TypeScript .NET).
4
4
 
5
- ## Documentation Ownership
5
+ Use this package to write Express-like apps in TypeScript and compile them to native binaries with `tsonic`.
6
6
 
7
- Use this split:
7
+ ## Quick Start (new project)
8
8
 
9
- - Runtime behavior, parity decisions, and architecture: `express-clr`
10
- - Package consumption, generation, and publishing workflow: `express` (this repo)
9
+ ```bash
10
+ mkdir my-api && cd my-api
11
+ tsonic init
11
12
 
12
- ## Versioning Model
13
+ # Install Express runtime + bindings (and required ASP.NET Core deps)
14
+ tsonic add npm @tsonic/express
15
+ npm run dev
16
+ ```
13
17
 
14
- This repo is versioned by .NET major:
18
+ Then open `http://localhost:3000/`.
15
19
 
16
- - .NET 10 -> `versions/10/` -> npm `@tsonic/express@10.x`
20
+ ## Hello World
17
21
 
18
- ## Install
22
+ ```ts
23
+ // packages/my-api/src/App.ts
24
+ import { express } from "@tsonic/express/index.js";
19
25
 
20
- ```bash
21
- npm install @tsonic/express @tsonic/dotnet @tsonic/core
26
+ export function main(): void {
27
+ const app = express.create();
28
+
29
+ app.get("/", (_req, res) => {
30
+ res.send("hello");
31
+ });
32
+
33
+ app.listen(3000);
34
+ }
22
35
  ```
23
36
 
24
- ## Usage
37
+ ## Basic API Surface
38
+
39
+ ### Create an app / router
25
40
 
26
41
  ```ts
27
42
  import { express } from "@tsonic/express/index.js";
28
43
 
29
44
  const app = express.create();
45
+ const router = express.Router();
46
+ ```
47
+
48
+ ### Routing
49
+
50
+ Common verbs:
51
+
52
+ ```ts
53
+ app.get("/health", (_req, res) => res.send("ok"));
54
+ app.post("/items", (req, res) => res.json(req.body));
55
+ app.put("/items/:id", (req, res) => res.send(req.params["id"]));
56
+ app.delete("/items/:id", (_req, res) => res.sendStatus(204));
57
+ app.patch("/items/:id", (_req, res) => res.sendStatus(204));
58
+ app.all("/anything", (_req, res) => res.send("matched"));
59
+ ```
60
+
61
+ ### Middleware
30
62
 
31
- app.get("/", (req, res) => {
32
- res.send("hello");
63
+ ```ts
64
+ app.use((req, _res, next) => {
65
+ // Do something with req
66
+ next();
33
67
  });
68
+ ```
69
+
70
+ Error middleware:
34
71
 
35
- app.listen(3000);
72
+ ```ts
73
+ app.use((err, _req, res, _next) => {
74
+ res.status(500).json({ error: String(err) });
75
+ });
36
76
  ```
37
77
 
38
- ## Generate Types
78
+ ### Request / Response
39
79
 
40
- ```bash
41
- npm run generate:10
80
+ `Request` highlights:
81
+
82
+ - `req.method`, `req.path`, `req.originalUrl`
83
+ - `req.query`, `req.params`
84
+ - `req.body` (when using body parsers)
85
+ - `req.get(name)` / `req.header(name)`
86
+
87
+ `Response` highlights:
88
+
89
+ - `res.status(code)`
90
+ - `res.send(body)`, `res.json(body)`, `res.sendStatus(code)`
91
+ - `res.redirect(path)` / `res.redirect(status, path)`
92
+ - `res.set(name, value)` / `res.header(name, value)`
93
+ - `res.cookie(name, value, options)` / `res.clearCookie(name, options)`
94
+
95
+ ### Body parsing
96
+
97
+ ```ts
98
+ app.use(express.json());
99
+ app.use(express.urlencoded());
100
+ app.use(express.text());
101
+ app.use(express.raw());
42
102
  ```
43
103
 
44
- The generator reads `express-clr` build outputs and regenerates `versions/10/`.
104
+ ### Static files
105
+
106
+ ```ts
107
+ app.use(express.static("./public"));
108
+ ```
45
109
 
46
- ## Publish
110
+ ### Listen / close
47
111
 
48
- ```bash
49
- npm run publish:10
112
+ ```ts
113
+ const server = app.listen(3000);
114
+ server.close();
50
115
  ```
51
116
 
52
- ## Documentation Map
117
+ ## Advanced docs
118
+
119
+ - https://github.com/tsoniclang/express/blob/main/docs/advanced.md (routers, handlers, middleware patterns)
120
+ - https://github.com/tsoniclang/express/blob/main/docs/deviations.md (known compatibility gaps / parity notes)
53
121
 
54
- - Generation workflow: `docs/generation.md`
55
- - Release workflow: `docs/release.md`
56
- - Current compatibility notes: `docs/deviations.md`
122
+ ## Versioning Model
123
+
124
+ This repo is versioned by .NET major:
125
+
126
+ - .NET 10 -> `versions/10/` -> npm `@tsonic/express@10.x`
57
127
 
58
128
  ## License
59
129