tribe / api
Tribe (v3) 的 JSON API
v1.0.15
2024-06-25 16:25 UTC
Requires
- alsvanzelf/jsonapi: ^2.4
- tribe/auth: ^3.0
- tribe/core: ^4.0
- dev-master
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.2
- v0.1.18
- v0.1.17
- v0.1.16
- v0.1.15
- v0.1.14
- v0.1.13
- v0.1.12
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-add-license-1
- dev-dev
This package is auto-updated.
Last update: 2024-09-25 17:01:34 UTC
README
基于 https://jsonapi.fullstack.org.cn/format 的 JSON API 实现
用法
授权
- 使用来自 Junction 生成的基本 HTTP 身份验证,使用 API 密钥(作为用户名)和 API 密码(作为密码)授权自己
- 保存返回的数组。数组中有一个名为 "access_token" 的列。这是用于访问数据的 Bearer 访问令牌。
数据处理
读取单个对象
对 /api/$type/$slug
或 /api/$id
发送 GET 请求
读取一个 $type 的多个对象或搜索
对 /api/$type
或 /api/search
发送 GET 请求
分页
对 /api/$type?index=0&limit=25
发送 GET 请求
排序
筛选
可以通过在 URL 中传递 "filter" 查询来选择所需的数据。
使用 GET
请求发送 ?filter=name,age,location,email
创建记录
对 /api/$type
发送 POST 请求,最好包括:user_id(创建者的 ID)和 content_privacy
编辑/更新记录
对 /api/$type/$slug
或 /api/$type/$id
发送 PATCH 请求
删除记录
对 /api/$type/$slug
或 /api/$type/$id
发送 DELETE 请求,必须包含:user_id(创建者的 ID)
上传界面
POST /api/file-upload
- 将项目中的
dist
下的tribe_upload.js
文件包含到你的项目中(或作为参考来实现自己的功能) - 创建一个按钮,你想为其编写上传程序,并使用
data-target='#input-file'
('#input-file' 可以是任何你想要的内容,但需要指定一个目标) - 通过传递事件发起者的选择器(即步骤 2 中创建的按钮)并定义 api URL
tribeUploadUrl
来初始化代码
<form action="#"> <input type="file" name="upload[]" id="upload" class="form-control mb-3" multiple> <button type="submit" class="btn btn-primary" id="form-submit" data-target="#upload">Submit</button> </form>
tribeUploadButton('#form-submit'); let tribeUploadUrl = '/api/file-upload'
重要信息
- 不能使用 API 删除或修改类型。唯一修改类型的方法是修改 Tribe 根目录中的 config/types.json。
- 不能使用 API 删除或修改多个记录。