[英]Tesla's “REST” API, and honk_horn end-point
GET /vehicles/{id}/command/honk_horn
正如在這篇文章中看到的:
https://news.ycombinator.com/item?id=7961944
關於honk_horn
資源應該使用什么動詞存在honk_horn
。 答案包括:
也許這里問題的根源在於honk_horn
是一個動作而不是資源,因此在這種特殊情況下,應該如何定義為 API 以在保持 RESTful 的同時發出命令?
也許這里問題的根源在於 honk_horn 確實是一個動作而不是資源
是的,我會這么說,這就是問題的核心。 面向資源和基於超媒體的方法可能如下所示(使用 Mason https://github.com/JornWildt/Mason來描述操作):
GET /vehicles/12345/horn => return status of horn (a resource in itself)
{
volume: 5,
numberOfHonks: 1025,
@actions:
{
"honk":
{
type: "void",
href: "/vehicles/12345/horn/honks",
method: "POST",
title: "POST here to honk horn once"
}
}
}
GET /vehicles/12345/horn/honks => return previous honks (a resource in itself)
{
numberOfHonks: 1025,
honks:
[
{ date: "2010-12-24T10:24:12" },
{ date: "2010-12-24T10:24:14" },
{ date: "2010-12-24T10:24:20" },
... 1022 other honks (or perhaps only latest top 100 honks)
]
}
POST /vehicles/12345/horn/honks => Add one honk (empty payload - or maybe even include volume and pitch ...)
有趣的練習:-)
Tesla API 不是 RESTful。 然而,它有一個有趣的一般結構:
有關更多詳細信息,請查看此處的文檔: https : //github.com/alibad/tesla-api-android/blob/main/API%20Guide/main.md
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.