update README.md of d1 blog server example

This commit is contained in:
syumai 2023-02-26 13:02:18 +09:00
parent e46e29aa7d
commit acf15ae798
2 changed files with 34 additions and 7 deletions

View File

@ -23,7 +23,7 @@
* [ ] Cache API
* [ ] Durable Objects
- [x] Calling stubs
* [ ] D1
* [x] D1 (alpha)
* [x] Environment variables
## Installation

View File

@ -9,21 +9,46 @@
* https://d1-blog-server.syumai.workers.dev
### Request
### Create blog post
```
curl --location --request POST 'https://simple-json-server.syumai.workers.dev/hello' \
$ curl --location --request POST 'https://d1-blog-server.syumai.workers.dev/articles' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "syumai"
"title":"example post",
"body":"body of the example post"
}'
{
"article": {
{
"id": "f9e8119e-881e-4dc5-9307-af4f2dc79891",
"title": "example post",
"body": "body of the example post",
"createdAt": 1677382874
}
}
}
```
### Response
### List blog posts
```json
```
$ curl 'https://d1-blog-server.syumai.workers.dev/articles'
{
"message": "Hello, syumai!"
"articles": [
{
"id": "bea6cd80-5a83-45f0-b061-0e13a2ad5fba",
"title": "example post 2",
"body": "body of the example post 2",
"createdAt": 1677383758
},
{
"id": "f9e8119e-881e-4dc5-9307-af4f2dc79891",
"title": "example post",
"body": "body of the example post",
"createdAt": 1677382874
}
]
}
```
@ -40,6 +65,8 @@ This project requires these tools to be installed globally.
### Commands
* Before development, 1. create your own D1 database, 2. set database ID to wrangler.toml and run `wrangler d1 migrations apply [DB Name]`.
```
make dev # run dev server
make build # build Go Wasm binary