TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: A Browse-able RESTish API

19 点作者 qixxiq超过 14 年前

3 条评论

numix超过 14 年前
I know that the meaning of REST has been diluted a lot, but this mostly RPC with pretty URLs.<p>I don't understand why they don't support PUT and DELETE. They are already using jQuery on the HTML implementation of their API site, so could use its Ajax library to provide cross-browser PUT and DELETE. If they wanted browser usable methods, they could have used the standard "_method" parameter along with POST, and convert it server-side.<p>This actually makes it a lot less discoverable for those of us not using the HTML view. For instance, when using curl to browse to /vi/client/list, I expect to get a list of clients. Instead, I get the following (I'd prefer to show JSON here, but I get a 500 when I try it.):<p><pre><code> curl -H "Accept: application/xml" https://api_test:submarine@api.snapbill.com/v1/client/list/ &#60;?xml version="1.0" encoding="UTF-8"?&#62; &#60;response xmlns="https://api.snapbill.com/" status="ok" type="form"&#62;&#60;fields&#62;&#60;field type="textbox" name="query"&#62;&#60;caption&#62;Search query&#60;/caption&#62;&#60;/field&#62;&#60;field type="number" name="page"&#62;&#60;class&#62;number&#60;/class&#62;&#60;default&#62;1&#60;/default&#62;&#60;caption&#62;Page&#60;/caption&#62;&#60;min&#62;1&#60;/min&#62;&#60;/field&#62;&#60;field type="number" name="perpage"&#62;&#60;class&#62;number&#60;/class&#62;&#60;default&#62;25&#60;/default&#62;&#60;caption&#62;Clients per page&#60;/caption&#62;&#60;max&#62;50&#60;/max&#62;&#60;min&#62;1&#60;/min&#62;&#60;/field&#62;&#60;/fields&#62;&#60;/response&#62; </code></pre> When I try to GET <a href="https://api_test:submarine@api.snapbill.com/v1/client/list/?number=2" rel="nofollow">https://api_test:submarine@api.snapbill.com/v1/client/list/?...</a>, I get the same response, which I was not expecting. I had to POST to the same URL in order to view the list, which is the wrong method.<p>There's also the issues of assuming a certain view in the end representation, including CSS and JS in their HTML representation, and having different default formats for different resources. All these make working with the API annoying.
hammerdr超过 14 年前
Why not just use the OPTIONS verb? You're overloading verbs in order to make your API discoverable.<p>Discoverability is great but there's a supported (and standard) way of accomplishing this already.<p>Examples:<p>GET /users<p>{users: [{name: 'Bob'}, {name: 'Alice'}]}<p>POST /users/create {name: 'Sally'}<p>{name: 'Sally', id: '3'}<p>OPTIONS /users<p>{links: [{rel: 'userList', url: '/users'}, {rel: 'addUser', url: '/users/create', verb: 'POST'}]}
评论 #2242516 未加载
评论 #2245714 未加载
jessedhillon超过 14 年前
What problem is this solving?<p>As a developer I don't want to click around in a web browser to see what I'm able to do at a particular API end point. I want good documentation to describe the system accurately.<p>Do you have good docs? If not, this browser-friendly stuff isn't going to make it easier for me to use. I don't want to look in Firebug or view source to figure out what parameters to POST.