daptin
0.10.3
下載 • 文件 • 社區
./daptin
.
. // logs truncated for brevity
.
INFO[2024-10-16 11:08:58] Listening websocket server at ... /live
INFO[2024-10-16 11:08:58] Our admin is [[email protected]]
INFO[2024-10-16 11:08:58] [ProcessId = 86403] Listening at port: :6336
INFO[2024-10-16 11:08:58] Get certificate for [Parths-MacBook-Pro.local]: true
INFO[2024-10-16 11:08:58] Listening at: [:6336]
INFO[2024-10-16 11:08:58] TLS server listening on port :6443
INFO[2024-10-16 11:09:03] Member says: Message < members: Joining from 192.168.0.125: 5336>
伺服器已啟動,使用 sqlite 資料庫,因為我們沒有指定 mysql 或 postgres。
呼叫註冊“action”api來建立一個新的user_account
curl ' http://localhost:6333/action/user_account/signup ' -X POST
--data-raw ' {"attributes":{"email":"[email protected]","password":"[email protected]","name":"[email protected]","passwordConfirm":"[email protected]"}} '
在新實例上,所有操作都允許由來賓執行,因此您不應該看到此內容
[
{
"Attributes" : {
"message" : " http error (403) forbidden and 0 more errors, forbidden " ,
"title" : " failed " ,
"type" : " error "
},
"ResponseType" : " client.notify "
}
]
你應該看到這個
[
{
"ResponseType" : " client.notify " ,
"Attributes" : {
"__type" : " client.notify " ,
"message" : " Sign-up successful. Redirecting to sign in " ,
"title" : " Success " ,
"type" : " success "
}
},
{
"ResponseType" : " client.redirect " ,
"Attributes" : {
"__type" : " client.redirect " ,
"delay" : 2000 ,
"location" : " /auth/signin " ,
"window" : " self "
}
}
]
curl ' http://localhost:6336/action/user_account/signin '
--data-raw ' {"attributes":{"email":"[email protected]","password":"[email protected]"}} '
[
{
" Attributes " : {
" key " : " token " ,
" value " : " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFydHBhckBnbWFpbC5jb20iLCJleHAiOjE3MjkzMjExMjIsImlhdCI6MTcyOTA2MTkyMiwiaXNzIjoiZGFwdGluLTAxOTIyOCIsImp0aSI6IjAxOTI5NDFmLTI2MGUtN2I0Ni1hMWFlLWYxMGZhZTcwMDE3OSIsIm5hbWUiOiJhcnRwYXJAZ21haWwuY29tIiwibmJmIjoxNzI5MDYxOTIyLCJzdWIiOiIwMTkyMmUxYS1kNWVhLTcxYzktYmQzZS02MTZkMjM3ODBmOTMifQ.H-GLmXCT-o7RxXrjo5Of0K8Nw5mpOOw6jgoXnd5KUxo "
},
" ResponseType " : " client.store.set "
},
{
" Attributes " : {
" key " : " token " ,
" value " : " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFydHBhckBnbWFpbC5jb20iLCJleHAiOjE3MjkzMjExMjIsImlhdCI6MTcyOTA2MTkyMiwiaXNzIjoiZGFwdGluLTAxOTIyOCIsImp0aSI6IjAxOTI5NDFmLTI2MGUtN2I0Ni1hMWFlLWYxMGZhZTcwMDE3OSIsIm5hbWUiOiJhcnRwYXJAZ21haWwuY29tIiwibmJmIjoxNzI5MDYxOTIyLCJzdWIiOiIwMTkyMmUxYS1kNWVhLTcxYzktYmQzZS02MTZkMjM3ODBmOTMifQ.H-GLmXCT-o7RxXrjo5Of0K8Nw5mpOOw6jgoXnd5KUxo; SameSite=Strict "
},
" ResponseType " : " client.cookie.set "
},
{
" Attributes " : {
" message " : " Logged in " ,
" title " : " Success " ,
" type " : " success "
},
" ResponseType " : " client.notify "
},
{
" Attributes " : {
" delay " : 2000,
" location " : " / " ,
" window " : " self "
},
" ResponseType " : " client.redirect "
}
]
我們將使用
export TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFydHBhckBnbWFpbC5jb20iLCJleHAiOjE3MjkzMjExMjIsImlhdCI6MTcyOTA2MTkyMiwiaXNzIjoiZGFwdGluLTAxOTIyOCIsImp0aSI6IjAxOTI5NDFmLTI2MGUtN2I0Ni1hMWFlLWYxMGZhZTcwMDE3OSIsIm5hbWUiOiJhcnRwYXJAZ21haWwuY29tIiwibmJmIjoxNzI5MDYxOTIyLCJzdWIiOiIwMTkyMmUxYS1kNWVhLTcxYzktYmQzZS02MTZkMjM3ODBmOTMifQ.H-GLmXCT-o7RxXrjo5Of0K8Nw5mpOOw6jgoXnd5KUxo
對於其餘的 api 呼叫。這是一個帶有以下資料的 JWT 令牌
{
"email" : " [email protected] " , // user email
"exp" : 1729321122 , // token expiry
"iat" : 1729061922 , // token issued at time
"iss" : " daptin-019228 " , // token issuer (your daptin instance)
"jti" : " 0192941f-260e-7b46-a1ae-f10fae700179 " , // unique identifier for this token
"name" : " [email protected] " , // user name
"nbf" : 1729061922 , // token valid not before timestamp
"sub" : " 01922e1a-d5ea-71c9-bd3e-616d23780f93 " // user reference id
}
因此,您有一個帳戶和一個用於驗證該帳戶的令牌。但你需要它嗎?否。
curl http://localhost:6333/api/user_account
{
"links" : {
"current_page" : 1 ,
"from" : 0 ,
"last_page" : 1 ,
"per_page" : 10 ,
"to" : 10 ,
"total" : 1
},
"data" : [
{
"type" : " user_account " ,
"id" : " 01929429-3d8f-7e53-8f15-a663e05fb01b " ,
"attributes" : {
"__type" : " user_account " ,
"confirmed" : 0 ,
"created_at" : " 2024-10-16T07:09:43.86360642Z " ,
"email" : " [email protected] " ,
"name" : " [email protected] " ,
"password" : " " ,
"permission" : 2097151 ,
"reference_id" : " 01929429-3d8f-7e53-8f15-a663e05fb01b " ,
"updated_at" : " 2024-10-16T07:09:43.863622045Z " ,
"user_account_id" : " 01929429-3d8f-7e53-8f15-a663e05fb01b "
},
"relationships" : { /// ... }
}
]
}
所有其他表(例如網站、雲端儲存、文件、使用者群組)中的所有資料也是如此。而且你也可以呼叫更新和刪除API(這裡沒有演示,但你可以嘗試,玩完後刪除sqlite資料庫檔案以將其全部重置)
作為第一個用戶,您可以選擇將其保持開啟或啟用多層權限並成為管理員
curl ' http://localhost:6336/action/world/become_an_administrator ' --compressed -X POST
-H " Authorization: Bearer $TOKEN " --data-raw ' {} '
此時,所有其他 api 都被鎖定,只有管理員(即您)可以存取。您希望向訪客或使用者開放少量或大量操作。
....將很快更新
https://github.com/daptin/daptin-js-client
入門套件:https://github.com/daptin/vue_typescript_starter_kit
定義模式
尋找
透過 ID 獲取
創造
刪除
刪除關係
列出關係
紅寶石 | Python | JavaScript |
打字稿 | PHP | 鏢 |
。 | 爪哇 | iOS系統 |
靈丹妙藥 | 右 | 珀爾 |
OpenAPI V3 規格是為每個公開的端點自動產生的。這可用於產生更多文件和客戶。
curl http://localhost/apispec.yaml