天道酬勤,学无止境

apiary

Trying to describe the request and response using Data Structures in API Blueprint

Question I'm trying to document an endpoint with API Blueprint, using the new Attributes and DataStructures sections of the spec. My request payload looks like this: { "url": "http://requestb.in/11v7i7e1", "active": true, "types": [ { "name": "sales", "version": "2.0" }, { "name": "products", "version": "2.0" } ] } My response payload looks something like that: { "data": { "id": "dc85058a-a683-11e4-ef46-e9431a15be8c", "url": "http://requestb.in/11v7i7e1", "active": true, "types": [ { "name": "products", "version": "2.0" }, { "name": "sales", "version": "2.0" } ] } } I tried the following API

2021-11-29 17:34:54    分类:技术分享    api   apiblueprint   apiary.io   apiary   MSON

Represent File Uploads in API Blueprints

Question We have an API end point where an image file can be uploaded along with the name of the file (a string) as well as a description (string). Apiary / API Blueprints won't allow me to have something like: + Request (multipart/form-data) + Headers Authorization: [key] + Attributes + name (string, required) - A human-readable name of the Catalog Item + description (string, optional) - A human readable description of the Catalog Item + image (file, optional) - An image file corresponding to the Catalog Item I get: base type 'file' is not defined in the document Is there a way to represent

2021-10-18 19:10:16    分类:技术分享    apiblueprint   apiary.io   apiary

Does Apiary.io and/or API Blueprint support api versioning?

Question Does api blueprint or Apiary.io support the notion of versioning your API? In particular, I'm versioning my API via the URI like this: GET /api/v2/SomeResource/ In the example above, this means I'm calling version 2 ("v2") of the API. Does api blueprint support this? How can I document multiple versions of a given action or the entire API? Answer1 You can use HOST header to signify that: HOST: http://example.com/api/v2 is going to prefix all resources with /api/v2. In the API Blueprint, if you use URL prefixing, the APIs are considered different and therefore you should use different

2021-09-29 03:07:09    分类:技术分享    rest   apiblueprint   apiary

MSON to describe object attributes in blueprint

Question I have an issue similar to what is described here. I have a JSON that looks like this: { "photos": [ { "key": "y37dmj10jkwof/moOIUB8912JKVgh", "caption": "A world of gamers.", "tags": [ "game", "japan" ], "attributes": { "copyright": true, "use": [ "public", "private" ] } } ] } and I am trying to describe the attributes using MSON, to render the blueprint. However, I am not successful at it. Here is my attempt: + Attributes (required, object) + photos (required, array) + (object) + key (required, string) - Photo key + caption (required, string) - Photo caption + tags (required, array)

2021-09-23 18:36:38    分类:技术分享    apiblueprint   apiary.io   apiary   MSON

How to add API version to Apiary Mock Server

Question Is there any way to add API version to Apiary Mock Server? Ex.: http://private-XXXXX-apiname.apiary-mock.com/v1/mocks/1?school_id=1 Answer1 Yes, when declaring HOST, you can append suffix to it and that is then propagated as prefix to all resources: FORMAT: 1A HOST: http://api.example.tld/v1/

2021-09-20 23:53:33    分类:技术分享    apiary.io   apiary

Create Mock Service API using Apiary

Question I'm attempting to create mock api services for testing purposes. We are already using Apiary on another team so I'm starting there. So far, I've noticed that if I want to have two separate calls requires mocking out of both requests. For example to get the notes with ids 1 and 2 requires explicitly writing out responses like: /notes/1 /notes/2 Is there a way to avoid this? Admittedly I'm still ramping up on creating blueprints. Answer1 Have a look at private-e9e59-pingdomcheck.apiary-mock.com/v1/gists/1. The number 1 is {id} here. You of course get only the general defined response

2021-09-18 17:42:55    分类:技术分享    apiblueprint   apiary.io   apiary

How do I send a JSON string in a POST request in Go

Question I tried working with Apiary and made a universal template to send JSON to mock server and have this code: package main import ( "encoding/json" "fmt" "github.com/jmcvetta/napping" "log" "net/http" ) func main() { url := "http://restapi3.apiary.io/notes" fmt.Println("URL:>", url) s := napping.Session{} h := &http.Header{} h.Set("X-Custom-Header", "myvalue") s.Header = h var jsonStr = []byte(` { "title": "Buy cheese and bread for breakfast." }`) var data map[string]json.RawMessage err := json.Unmarshal(jsonStr, &data) if err != nil { fmt.Println(err) } resp, err := s.Post(url, &data

2021-04-10 05:04:59    分类:技术分享    json   rest   go   apiary