Skip to content

Commit abdc96f

Browse files
author
takeshi iijima
committed
fix: update example configuration and documentation
- Fix file paths in example/api.json to work from root directory - Update example README with clearer instructions - Add run.sh script for easier example execution
1 parent 56ebb0d commit abdc96f

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

example/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ curl http://localhost:3000/static/index.html
6767
# Or open in browser: http://localhost:3000/static/index.html
6868
```
6969

70+
## Note on File Paths
71+
72+
The paths in the `api.json` configuration file are relative to the directory from which you run the server, not the location of the configuration file itself. This means that when running from the project root, all paths include the `example/` prefix, like:
73+
74+
```json
75+
{
76+
"jsonPath": "./example/health-check.json"
77+
}
78+
```
79+
80+
If you want to run the server while in the example directory, you would need to modify the paths in `api.json` to remove the `example/` prefix.
81+
7082
## Customizing
7183

7284
Feel free to modify these example files or create your own to experiment with the Go JSON Server's capabilities.

example/api.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,47 @@
77
"method": "GET",
88
"status": 200,
99
"path": "/",
10-
"jsonPath": "./health-check.json"
10+
"jsonPath": "./example/health-check.json"
1111
},
1212
{
1313
"method": "GET",
1414
"status": 200,
1515
"path": "/users",
16-
"jsonPath": "./users.json"
16+
"jsonPath": "./example/users.json"
1717
},
1818
{
1919
"method": "GET",
2020
"status": 200,
2121
"path": "/user/:id",
22-
"jsonPath": "./user-detail.json"
22+
"jsonPath": "./example/user-detail.json"
2323
},
2424
{
2525
"method": "GET",
2626
"status": 200,
2727
"path": "/posts",
28-
"jsonPath": "./posts.json"
28+
"jsonPath": "./example/posts.json"
2929
},
3030
{
3131
"method": "GET",
3232
"status": 200,
3333
"path": "/posts/:id",
34-
"jsonPath": "./post-detail.json"
34+
"jsonPath": "./example/post-detail.json"
3535
},
3636
{
3737
"method": "GET",
3838
"status": 200,
3939
"path": "/users/:userId/posts/:postId",
40-
"jsonPath": "./user-post.json"
40+
"jsonPath": "./example/user-post.json"
4141
},
4242
{
4343
"method": "POST",
4444
"status": 201,
4545
"path": "/users",
46-
"jsonPath": "./user-created.json"
46+
"jsonPath": "./example/user-created.json"
4747
},
4848
{
4949
"path": "/static",
50-
"folder": "./static"
50+
"folder": "./example/static"
5151
}
5252
]
5353
}

example/run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Change to the root directory of the project
4+
cd $(dirname $0)/..
5+
6+
# Run the server with the example configuration
7+
go run go-json-server.go --config=./example/api.json

0 commit comments

Comments
 (0)