How to specify request headers in API Blueprint - apiblueprint

I am trying to define an API blueprint for a resource that utilises request headers to understand what content type to return.
## Offer [/offers/{offerCode}]
+ Parameters
+ offerCode: summer2015 (required, string) - alphanumeric offer code
### View an Offer Detail [GET]
+ Response 200 (application/vnd.v0.1.0+json)
{
........
}
I want my request to be as follows:-
GET /offers/summer2015 HTTP/1.1
Host: my.api.com
Accept: application/vnd.v0.1.0+json
How can I document that using API Blueprint?

I'm not sure if I understand what you want to achieve but I'd say that you want to specify header for request and you can do that by specifying request the same way as response.
## Offer [/offers/{offerCode}]
+ Parameters
+ offerCode: summer2015 (required, string) - alphanumeric offer code
### View an Offer Detail [GET]
+ Request
+ Headers
Accept: application/vnd.v0.1.0+json
+ Response 200 (application/vnd.v0.1.0+json)
{
........
}

Related

Apache Camel graphql custom header request

I have tried to make GraphQL request with Apache Camel graphql component. Is there any way to setup custom header in qraphql POST request?
I tried to put in header key/value param, but there is no efect on HTTP header.
from("quartz://" + "MyRoute" + "?cron=0 */1 * * * ?")
.setHeader("X-Custom-Header-Token",constant("myValueOfCustomHeader"))
.setHeader("GplQuery", constant(query))
.setHeader("GplVariable",constant(vars))
.to("graphql://https://domain/v1/graphql.json?" +
"query=GplQuery&variables=GplVariable")
.to("direct:" + "log_response")
.end();
With this example, I have got request without "X-Custom-Header-Token" in HTTP header.

apiary authentication description not work?

I currently have this blueprint as https://help.apiary.io/api_101/apib-authentication/#describing-basic-auth-in-api-blueprint described.
FORMAT: 1A
# Basic Auth API
## Basic Auth protected resource [/protected]
### Status [GET]
+ Response 401
+ Headers
WWW-Authenticate: Basic realm="protected"
+ Request
+ Headers
Authorization: Basic dTE6dDE=
+ Response 200 (application/json)
{
"status": "ok"
}
But it won't work, the api endpoint would pop up asking for username/pwd and I entered the corresponding pair u1:p1 it will just pop up the window again.
Does anyone have insight on this? Thanks so much in advance!

Power Query call to google.webmaster.api , Post, request problem

I call the google.webmasters.api via Power-Query(M) and managed to configure the oath2 and made my first successfull call to get & list.
Now i try to call the /searchAnalytics/query? which is working only with Post.
This always responds in a 400 error. Formating of the Query or the Url is not working correctly.
Here some additional Infomations:
Power Query - Reference
Google Webmaster Api - Reference
PowerBi Community
format Date different:
body = "{ ""startDate"": ""2019-01-01"", ""endDate"": ""2019-02-02"" }",
to
body = "{ ""startDate"": ""2019/01/01"", ""endDate"": ""2019/02/02"" }",
let
body = "{ ""startDate"": ""2019-01-01"", ""endDate"": ""2019-02-02"" }",
AccessTokenList = List.Buffer(api_token),
access_token = AccessTokenList{0},
AuthKey = "Bearer " & access_token,
url = "https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fxxxxxxxxx.xxx/searchAnalytics/query?",
Response = Web.Contents(url, [Headers=[Authorization=AuthKey, ContentType="application/json", Accept="application/json"], Content=Text.ToBinary(body) ]),
JsonResponse = Json.Document(Response)
in
Response
getting a 400 and is shows as 400 call in Gooogle-Api Overview
Any Ideas whats wrong?
Thx
Ensure request headers are valid. Server expects Content-Type header, not ContentType.
The documentation (https://developers.google.com/webmaster-tools/search-console-api-original/v3/searchanalytics/query#try-it) suggest requests should be something like:
POST https://www.googleapis.com/webmasters/v3/sites/[SITEURL]/searchAnalytics/query HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{}
So seems like main takeaways are:
HTTP POST method must be used
Web.Contents documentation (https://learn.microsoft.com/en-us/powerquery-m/web-contents) suggests including the Content field in the options record to change request from GET to POST.
URL must be valid
You haven't provided your actual URL, so you'll have to validate it for yourself. I would get rid of the trailing ? in your url (as you aren't including a query string -- and even if you were, you should pass them to the Query field of the options record instead of building the query string yourself).
Headers (Authorization, Accept, Content-Type) should be valid/present.
Build your headers in a separation expression. Then pass that expression to the Headers field of the options record. This gives you the chance to review/inspect your headers (to ensure they are as intended).
Body should contain valid JSON to pass to the API method.
Creating valid JSON via manual string concatenation is liable to error. Using Json.FromValue (https://learn.microsoft.com/en-us/powerquery-m/json-fromvalue) seems a better approach.
All in all, your M code might look something like:
let
// Some other code is needed here, in which you define the expression api_token
AccessTokenList = List.Buffer(api_token),
access_token = AccessTokenList{0},
AuthKey = "Bearer " & access_token,
requestHeaders = [Authorization = AuthKey, #"Content-Type" = "application/json", Accept = "application/json"],
parametersToPost = [startDate = "2019-01-01", endDate = "2019-02-02"], // Can include other parameters here e.g. dimensions, as mentioned in Search Console API documentaton.
jsonToPost = Json.FromValue(parametersToPost, TextEncoding.Utf8), // Second argument not required (as is default), but just be explicit until you've got everything working.
url = "https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fxxxxxxxxx.xxx/searchAnalytics/query", // Uri.EscapeDataString function can be use for URL encoding
response = Web.Contents(url, [Headers=requestHeaders, Content=jsonToPost])
in
response
Untested (as I don't have an account or API credentials).

$stateProvider requests template in templateURL with accept header as application/json which must be text/html

when we are actually requesting for a template url . The accept header is always application/json instead of text/html
I am currently Using nancy for generating both template and api request based on the content request type on accept headers .
Something like this
private dynamic Index(dynamic parameters)
{
Students = NancyContext.Set<Student>().ToList();
Negotiate.WithView("Index").WithModel(Students);
}
which basically when requested with application/json returns json . And when requested with text/html then it returns the template with model . But since its requesting the template with application/json . Its only returning json for the api request and not the template . Any workaround for to change the accept header to text/html instead of application/json for template url ?
IT was feature which was supposed to be integrated . So it has been integrated into
#1287

How can I specify multiple request types per endpoint in API Blueprint?

Is it possible to define what happens when PUT to /asdf with an empty request body happens vs PUT to /asdf with this request body with { "value": "somthing" }.
Assuming the media type of both requests is the same and the response HTTP status codes differs this should be legit:
# PUT /asdf
+ Request Empty (application/json)
+ Headers
Content-Lenght: 0
+ Response 400
+ Request With Value (application/json)
{ "value": "somthing" }
+ Response 204

Resources