From acf15ae79822b5b42bc2fe94d8c91a3e37ecbc4b Mon Sep 17 00:00:00 2001 From: syumai Date: Sun, 26 Feb 2023 13:02:18 +0900 Subject: [PATCH] update README.md of d1 blog server example --- README.md | 2 +- examples/d1-blog-server/README.md | 39 ++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d4b6f88..f254e5d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ * [ ] Cache API * [ ] Durable Objects - [x] Calling stubs -* [ ] D1 +* [x] D1 (alpha) * [x] Environment variables ## Installation diff --git a/examples/d1-blog-server/README.md b/examples/d1-blog-server/README.md index 37271d4..1797e58 100644 --- a/examples/d1-blog-server/README.md +++ b/examples/d1-blog-server/README.md @@ -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