Skip to content

Commit f379208

Browse files
authored
Merge pull request #333 from spinframework/feat/router-sample
[examples]: Updated router-sample
2 parents 4b8686d + 7ceb92c commit f379208

File tree

4 files changed

+319
-415
lines changed

4 files changed

+319
-415
lines changed

examples/common-patterns/routing-requests/README.md

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,48 @@ spin build
99
spin up
1010
```
1111

12-
To test the different routes, run the following commands:
12+
## Testing Endpoints
1313

14-
```bash
14+
To test the different endpoints registered using the `itty-router`, run the following commands:
15+
16+
### Sending a `GET` request to `/`
17+
18+
```console
1519
curl localhost:3000/
16-
# hello universe
17-
curl localhost:3000/hello/spin
18-
# Hello spin
20+
# Hello, Fermyon
21+
```
22+
23+
### Sending a `GET` request to `/hello/:name`
24+
25+
```console
26+
# Passing "Spin" for the route parameter :name
27+
curl localhost:3000/hello/Spin
28+
# Hello, Spin
29+
```
30+
31+
### Sending a `GET` request to `/bye/:name`
32+
33+
```console
34+
# Passing "Spin" for the route parameter :name
35+
curl localhost:3000/bye/Spin
36+
# {"message": "Goodbye, Spin"}
37+
```
38+
39+
### Sending a `GET` request to `/reverse-header-value`
40+
41+
```console
42+
# Specifying the x-spin-demo header and printing response headers
43+
curl -i -H 'x-spin-demo:hello spin' localhost:3000/reverse-header-value
44+
# HTTP/1.1 200 OK
45+
# x-spin-demo: nips olleh
46+
# content-length: 0
47+
# date: Mon, 17 Feb 2025 13:52:52 GMT
48+
```
49+
50+
### Sending a `POST` request to `/items`
51+
52+
```console
53+
# Passing a JSON payload
54+
curl -XPOST -H 'content-type:application/json' -d '{ "message": "hello"}' localhost:3000/items
55+
# Item processed
1956
```

0 commit comments

Comments
 (0)