This folder contains a [jsonstore](https://github.com/bluzi/jsonstore)-like storage service. But is multi-threaded and stores everything in memory. Serving as a showcase on how to build a minimally useful RESTful APIs in Drogon.
## API
#### /get-token
Generate a token that the user can use to create, read, modify and delete records.
* **method**: GET
* **URL params**: None
* **Body**: None
* **Success response**
* **Code**: 200
* **Content**: `{"token":"3a322920d42ef0763152a6efff2ed51985530aedd45370f92fd0f0b8dcc30220"}`
* **Sample call**
```bash
❯ curl -XGET http://localhost:8848/get-token
{"token":"3a322920d42ef0763152a6efff2ed51985530aedd45370f92fd0f0b8dcc30220"}
```
#### /{token}
Create a new JSON object associated with the token
* **method**: POST
* **URL params**: None
* **Body**: The initial JSON object to store
* **Success response**
* **Code**: 200
* **Content**: `{"ok":true}`
* **Failed response**:
* **Code**: 500
* **Why**: Either the token already is associated with the data or request body/content-type is not JSON.
* **Content**: `{"ok":false}`
* **Sample call**
```bash
❯ curl -XPOST http://localhost:8848/3a322920d42ef0763152a6efff2ed51985530aedd45370f92fd0f0b8dcc30220 \
-H 'content-type: application/json' -d '{"foo":{"bar":42}}'
{"ok":true}
```
Delete the JSON object associated with the token
* **method**: DELETE
* **URL params**: None
* **Body**: None
* **Success response**
* **Code**: 200
* **Content**: `{"ok":true}`
* **Sample call**
```bash
❯ curl -XDELETE http://localhost:8848/3a322920d42ef0763152a6efff2ed51985530aedd45370f92fd0f0b8dcc30220
{"ok":true}
```
#### /{token}/{some/path/to/data}
Retrieve data at and below the specified path
* **method**: GET
* **URL params**: None
* **Body**: None
* **Success response**
* **Code**: 200
* **Content**: `{"foo":{"bar":42}}`
* **Failed response**:
* **Code**: 500
* **Why**: No data associated with the provided token, or it does not exist in the JSON object.
* **Content**: `{"ok":false}`
* **Sample call**
```bash
❯ curl -XGET http://localhost:8848/3a322920d42ef0763152a6efff2ed51985530aedd45370f92fd0f0b8dcc30220/
{"foo":{"bar":42}}
```
Update data at the specified path
* **method**: PUT
* **URL params**: None
* **Body**: The JSON object you wish to replace to
* **Success response**
* **Code**: 200
* **Content**: `{"ok":true}`
* **Failed response**:
* **Code**: 500
* **Why**: No data associated with the provided token or it does not exist in the JSON object.
* **Content**: `{"ok":false}`
* **Sample call**
```bash
❯ curl -XPUT http://localhost:8848/3a322920d42ef0763152a6efff2ed51985530aedd45370f92fd0f0b8dcc30220/foo \
-H 'content-type: application/json' -d '{"fruit":"apple"}'
{"ok":true}
```
## Example use
```bash
export URL="http://localhost:8848"
export TOKEN=`curl $URL/get-token -s | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
printf "Token is: $TOKEN\n"
printf 'Creating new data \n> '
curl -XPOST $URL/$TOKEN -H 'content-type: application/json' -d '{"foo":{"bar":42}}'
printf '\nRetrieving value of data["foo"]["bar"] \n> '
curl $URL/$TOKEN/foo/bar
printf '\nModifing data \n> '
curl -XPUT $URL/$TOKEN/foo -H 'content-type: application/json' -d '{"zoo":"zebra"}'
printf '\nNow data["foo"]["bar"] no longer exists \n> '
curl $URL/$TOKEN/foo/bar
printf '\nDelete data \n> '
curl -XDELETE $URL/$TOKEN
echo
```
Output:
```
Token is: 5e73ba044b45e68b4856925faea268391091f39fc62ab8c58955cf20957018fa
Creating new data
> {"ok":true}
Retrieving value of data["foo"]["bar"]
> 42
Modifying data
> {"ok":true}
Now data["foo"]["bar"] no longer exists
> {"ok":false}
Delete data
> {"ok":true}
```
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Drogon是一个基于C++17/20的Http应用框架,使用Drogon可以方便的使用C++构建各种类型的Web应用服务端程序。 本版本库是github上Drogon工程的镜像库。Drogon是作者非常喜欢的美剧《权力的游戏》中的一条龙的名字(汉译作卓耿),和龙有关但并不是dragon的误写,为了不至于引起不必要的误会这里说明一下。Drogon是一个跨平台框架,它支持Linux,也支持macOS、FreeBSD,OpenBSD,HaikuOS,和Windows。
资源推荐
资源详情
资源评论
收起资源包目录
Drogon是一个基于C++17/20的Http应用框架,使用Drogon可以方便的使用C++构建各种类型的Web应用服务端程序 (541个子文件)
test.c 6KB
mman.c 4KB
db_test.cc 123KB
Users.cc 55KB
Groups.cc 53KB
main.cc 52KB
create_model.cc 48KB
Users.cc 48KB
Users.cc 48KB
HttpServer.cc 44KB
HttpAppFrameworkImpl.cc 40KB
Utilities.cc 33KB
HttpRequestImpl.cc 32KB
HttpResponseImpl.cc 29KB
HttpControllersRouter.cc 27KB
HttpUtils.cc 24KB
ConfigLoader.cc 24KB
HttpClientImpl.cc 22KB
DbClientLockFree.cc 21KB
StaticFileRouter.cc 21KB
AccessLogger.cc 20KB
Blog.cc 20KB
Blog.cc 20KB
Blog.cc 20KB
Wallets.cc 19KB
Wallets.cc 18KB
create_view.cc 18KB
Wallets.cc 18KB
MysqlConnection.cc 18KB
DbClientImpl.cc 18KB
RedisConnection.cc 18KB
HttpRequestParser.cc 17KB
RedisClientImpl.cc 16KB
PgBatchConnection.cc 16KB
create_controller.cc 15KB
WebSocketClientImpl.cc 15KB
api_v1_ApiTest.cc 15KB
RedisClientLockFree.cc 14KB
Tag.cc 14KB
Tag.cc 14KB
Tag.cc 14KB
WebSocketConnectionImpl.cc 14KB
Category.cc 14KB
Category.cc 14KB
Category.cc 14KB
BlogTag.cc 14KB
BlogTag.cc 14KB
BlogTag.cc 14KB
main.cc 14KB
TransactionImpl.cc 13KB
PgConnection.cc 11KB
HttpResponseParser.cc 11KB
MultipartStreamParser.cc 10KB
Sqlite3Connection.cc 10KB
press.cc 10KB
PgListener.cc 10KB
DbClientManager.cc 9KB
SqlBinder.cc 9KB
GzipTest.cc 9KB
SharedLibManager.cc 9KB
drogon_test.cc 8KB
Hodor.cc 8KB
Chat.cc 8KB
MultiPart.cc 8KB
ArrayParser.cc 7KB
CoroutineTest.cc 7KB
PromExporter.cc 7KB
main.cc 6KB
ListenerManager.cc 6KB
DigestAuthFilter.cc 6KB
SlashRemover.cc 6KB
MiddlewaresFunction.cc 6KB
RealIpResolver.cc 6KB
RedisSubscriberImpl.cc 6KB
test1.cc 6KB
redis_test.cc 6KB
AOPAdvice.cc 5KB
RequestStream.cc 5KB
HttpFileImpl.cc 5KB
RequestStreamExampleCtrl.cc 5KB
SlashRemoverTest.cc 5KB
RequestStreamTest.cc 5KB
RequestStreamTestCtrl.cc 5KB
RangeParser.cc 5KB
db_api_test.cc 5KB
test1.cc 5KB
RealIpResolverTest.cc 5KB
test1.cc 5KB
WsClient.cc 4KB
PipeliningTest.cc 4KB
MultiPartParserTest.cc 4KB
Criteria.cc 4KB
MiddlewareTest.cc 4KB
RedisClientManager.cc 4KB
create_project.cc 4KB
SubscribeContext.cc 4KB
RedisTransactionImpl.cc 4KB
Result.cc 4KB
SecureSSLRedirector.cc 4KB
SessionManager.cc 4KB
共 541 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7364
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功