<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>RESTful on 施国鹏 (seth-shi)</title><link>https://sethix.com/zh-cn/tags/restful/</link><description>Recent content in RESTful on 施国鹏 (seth-shi)</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Thu, 05 Apr 2018 21:11:41 +0800</lastBuildDate><atom:link href="https://sethix.com/zh-cn/tags/restful/index.xml" rel="self" type="application/rss+xml"/><item><title>RESTful 在路由 URL 有名义的写法</title><link>https://sethix.com/zh-cn/posts/2018040521/</link><pubDate>Thu, 05 Apr 2018 21:11:41 +0800</pubDate><guid>https://sethix.com/zh-cn/posts/2018040521/</guid><description> 前边已经有过一篇博客简单的介绍在Laravel 中使用 RESTful 这篇文章介绍一下各种RESTful风格路由的写法，不一定是正确，但是个人觉得写这样的路由很有含义。 基础路由 一般放在一个组里，其他路由总要带上这个前缀 总是API **+**版本号 /api/v1 基本参数 分页的参数，直接使用QueryString limit page /url?limit=10&amp;amp;page=1 多参数排序 /url?desc=created_at,id&amp;amp;asc=grade,updated_at 基本的路由 分类列表 method: get /categories 创建分类 method: post /categories 删除分类 method: delete /categories/{category} 单个分类 method: get /catagories/{catagory} 修改分类 method: put /categories/{category} 稍微复杂的路由 获取分类下的所有文章 method: get /categories/{category}/articles 获取标签下的所有文章 method: get /tags/{tag}/articles 批量删除文章 （尽量不要进行批量操作） method: delete /article/batch?id=1,2,3 认证的路由 通常情况下都可以使用(名义明确的) 登录 method: post /login 注销 method: post /logout 但是为了符合RESTful风格，我们也可以换个名字 登录 (实际上就是创建一个 token) method: post /tokens 注销 (实际上就是删除 token) method: delete /tokens/{token} 长名字路由 有时候总不可避免的出现路由名字多个单词组合 这时候我们可以使用中划线分隔，更利于seo优化 获取某种文章类型的文章 method: get /article-types/{article_type}/articles</description></item></channel></rss>