Closed alimy closed 9 months ago
package v1
// Site v1 service
Site[v1] {
_ Chain
Index Get `/index/`
Articles Get `/articles/:category/`
Category Get `/category/`
PostArticle Post `/articles/:category/`
}
package v2
// Site v2 service
Site[v2] {
_ Chain
Index Get `/index/`
Articles Get `/articles/:category/`
Category Get `/category/`
PostArticle Post `/articles/:category/`
}
package v1
// Site v1 service
Site v1 {
_ Chain
Index Get `/index/`
Articles Get `/articles/:category/`
Category Get `/category/`
PostArticle Post `/articles/:category/`
}
package v2
// Site v2 service
Site v2 {
_ Chain
Index Get `/index/`
Articles Get `/articles/:category/`
Category Get `/category/`
PostArticle Post `/articles/:category/`
}
package v1
// Site v1 service
service Site(v1 Group, _ Chain) {
Index Get `/index/`
Articles Get `/articles/:category/`
Category Get `/category/`
PostArticle Post `/articles/:category/`
}
package v2
// Site v2 service
service Site(v2 Group, _ Chain) {
Index Get `/index/`
Articles Get `/articles/:category/`
Category Get `/category/`
PostArticle Post `/articles/:category/`
}
package v1
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int
Msg string
PostId string `json:"postid"`
}
// Site v1 service
service Site(v1) {
Index Get(/index/)
Articles Get(/articles/:category/)
Category Get(/category/)
PostArticle Post(/articles/:category/) {
Request(ArticleReq) {
contentType: application/json
}
Response(ArticleRes) {
contentType: application/json
}
}
}
package v2/core
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int
Msg string
PostId string `json:"postid"`
}
package v2
import v2/core
// Site v2 service
service Site(v2 Group, _ Chain) {
Index Get(/index/)
Articles Get(/articles/:category/)
Category Get(/category/)
PostArticle Post(/articles/:category/) {
Request(core.ArticleReq) {
contentType: application/json
}
Response(core.ArticleRes) {
contentType: application/json
}
}
}
package v1
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int
Msg string
PostId string `json:"postid"`
}
// Site v1 service
service Site(v1) {
Index Get(/index/)
Articles Get(/articles/:category/)
Category Get(/category/)
PostArticle Post(/articles/:category/) {
Request(body: ArticleReq) {
contentType: application/json
}
Response(body: ArticleRes, contentType: application/json)
}
}
package v2/core
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int
Msg string
PostId string `json:"postid"`
}
package v2
import v2/core
// Site v2 service
service Site(group: v2, chain: _) {
Index Get(/index/)
Articles Get(/articles/:category/)
Category Get(/category/)
PostArticle Post(/articles/:category/) {
Request(body: core.ArticleReq, contentType: application/json)
Response(body: core.ArticleRes) {
contentType: application/json
}
}
}
package v1
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int
Msg string
PostId string `json:"postid"`
}
// Site v1 service
service Site(v1) {
Index Get(/index/)
Articles Get(/articles/:category/)
Category Get(/category/)
PostArticle Post(/articles/:category/) {
Request(body: ArticleReq) {
content-type: application/json,
}
Response(body: ArticleRes) {
content-type: application/json,
}
}
}
package v2/core
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int
Msg string
PostId string `json:"postid"`
}
package v2
import v2/core
// Site v2 service
service Site(group: v2, chain: _) {
Index Get(/index/)
Articles Get(/articles/:category/)
Category Get(/category/)
PostArticle Post(/articles/:category/) {
Request(body: core.ArticleReq) {
content-type: application/json,
}
Response(body: core.ArticleRes) {
content-type: application/json,
}
}
}
package v1
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int
Msg string
PostId string `json:"postid"`
}
// Site v1 service
service Site(group: v1) {
Index get(/index/)
Articles get(/articles/:category/)
Category get(/category/)
PostArticle post(/articles/:category/) {
request(body: ArticleReq) {
Content-Type: application/json,
}
response(body: ArticleRes) {
Content-Type: application/json,
}
}
}
package v2/core
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int
Msg string
PostId string `json:"postid"`
}
message IndexHead {
LastTime string `head:"x-last-time"`
}
package v2
import v2/core
// Site v2 service
service Site(group: v2, chain: _) {
Index get(/index/) {
request(head: core.IndexHead)
}
Articles get(/articles/:category/)
Category get(/category/)
PostArticle post(/articles/:category/) {
request(body: core.ArticleReq) {
Content-Type: application/json,
}
response(body: core.ArticleRes) {
Content-Type: application/json,
}
}
}
%> cat site_v1.m2
//mir:syntax v0.1-alpha.1
package v1
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int `json:"code"`
Msg string `json:"msg"`
PostId string `json:"postid"`
}
// Site v1 service
service Site(group: v1) {
Index() `get:"/index/"`
Articles() `get:"/articles/:category/"`
Category() `get:"/category/"`
PostArticle(article ArticleReq) ArticleRes `post:"/articles/:category/"`
}
%> cat common.m2
//mir:syntax v0.1-alpha.1
package core
message ArticleReq {
Content string `json:"content"`
}
message ArticleRes {
Code int `json:"code"`
Msg string `json:"msg"`
PostId string `json:"postid"`
}
message IndexHead {
LastTime string `param:"lastTime"`
}
%> cat site_v2.m2
//mir:syntax v0.1-alpha.1
package v2
import core
// Site v2 service
service Site(group: v2, chain: _) {
Index(param core.indexParam) `get:"/index"`
Articles() `get, post:"/articles/:category/"`
Category() `get:"/category/"`
PostArticle(article core.ArticleReq) core.ArticleRes `post:"/articles/:category/"`
}
确定使用 Thrift IDL 来定义RESTful接口。详情参看 #43.