{"id":430,"date":"2018-01-18T13:22:41","date_gmt":"2018-01-18T04:22:41","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2018\/01\/18\/api_blueprint_dredd"},"modified":"2022-10-28T22:37:53","modified_gmt":"2022-10-28T13:37:53","slug":"api_blueprint_dredd","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2018\/01\/18\/api_blueprint_dredd\/","title":{"rendered":"API Blueprint\u3067\u66f8\u3044\u305fAPI\u4ed5\u69d8\u66f8\u3092Dredd\u3092\u4f7f\u3063\u3066CircleCI\u3067\u30c6\u30b9\u30c8\u3057\u3066\u307f\u305f"},"content":{"rendered":"

\u4eca\u56de\u3001\u3042\u308b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067 API Blueprint<\/a> \u3092\u4f7f\u3063\u3066\u3001API\u4ed5\u69d8\u66f8\u3092\u66f8\u304f\u3053\u3068\u306b\u306a\u3063\u305f\u306e\u3067\u3001 API Blueprint<\/code> \u306b\u3064\u3044\u3066\u8abf\u3079\u3066\u3044\u305f\u306e\u3060\u304c\u3001 Dredd<\/a> \u3068\u3044\u3046API\u306e\u30c6\u30b9\u30c8\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304c\u4fbf\u5229\u305d\u3046\u3060\u3063\u305f\u306e\u3067\u3001 CircleCI<\/code> \u3067\u7c21\u5358\u306a\u30c6\u30b9\u30c8\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u89e6\u3063\u3066\u307f\u305f\u3002<\/p>\n

Dredd<\/code> \u306f\u3001 apiary.io<\/code> \u304c\u63d0\u4f9b\u3057\u3066\u3044\u308bAPI\u306e\u30c6\u30b9\u30c8\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3001 API Blueprint<\/code> \u3060\u3051\u3067\u306f\u306a\u304f\u3001 Swagger<\/a> \u306b\u3082\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3002<\/p>\n

\u8a66\u3057\u3066\u307f\u305f<\/h2>\n

API\u4f5c\u6210<\/h3>\n

\u307e\u305a\u306f Golang<\/code> \u3067\u975e\u5e38\u306b\u7c21\u5358\u306a API<\/code> \u3092\u4f5c\u6210\u3002
\n\/message<\/code> \u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001 Hello World!!<\/code> \u304c\u8fd4\u308b\u3060\u3051\u3002<\/p>\n

package main\n\nimport (\n    "fmt"\n    "net\/http"\n    "os"\n)\n\nfunc main() {\n    http.HandleFunc("\/message", index)\n\n    p := port()\n    fmt.Println("Listening on Port", p)\n    http.ListenAndServe(p, nil)\n}\n\nfunc port() string {\n    port := os.Getenv("PORT")\n    if len(port) == 0 {\n        port = "8080"\n    }\n    return ":" + port\n}\n\nfunc index(w http.ResponseWriter, r *http.Request) {\n    w.WriteHeader(http.StatusOK)\n    fmt.Fprintln(w, "Hello World!!")\n}<\/code><\/pre>\n

go build<\/code> \u3092\u3057\u3066\u3001\u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3002<\/p>\n

$ .\/simple-go-server\nListening on Port :8080<\/code><\/pre>\n

\u5225\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u3001 curl<\/code> \u3092\u5b9f\u884c\u3057\u3066\u3061\u3083\u3093\u3068\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u8fd4\u3063\u3066\u304f\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n

$ curl localhost:8080\/message\nHello World!!<\/code><\/pre>\n

API Blueprint \u3067\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u4f5c\u6210<\/h3>\n

API Blueprint<\/code> \u5f62\u5f0f\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8 doc.apib<\/code> \u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n

FORMAT: 1A\n\n# GET \/message\n+ Response 200 (text\/plain; charset=utf-8)\n\n        Hello World!!<\/code><\/pre>\n

Dredd \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n

Node.js<\/code> \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6e08\u307f\u306e\u74b0\u5883\u3067\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066 Dredd<\/code> \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n

$ npm install -g dredd\n$ dredd --version<\/code><\/pre>\n

Dredd \u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210<\/h3>\n

dredd init<\/code> \u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u5bfe\u8a71\u5f62\u5f0f\u3067\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb dredd.yml<\/code> \u304c\u4f5c\u6210\u3067\u304d\u308b\u3002<\/p>\n

$ dredd init\n? Location of the API description document doc.apib\n? Command to start API backend server e.g. (bundle exec rails server) .\/simple-go-server\n? URL of tested API endpoint localhost:8080\n? Programming language of hooks go\n? Do you want to use Apiary test inspector? No\n? Dredd is best served with Continuous Integration. Create CircleCI config for Dredd? No\n\nConfiguration saved to dredd.yml\n\nInstall hooks handler and run Dredd test with:\n\n  $ go get github.com\/snikch\/goodman\/cmd\/goodman\n  $ dredd<\/code><\/pre>\n