How to specify Content-Type of all responses once in API Blueprint? - apiblueprint

In order to satisfy Dredd, I have to write this for every response in my API Blueprint document:
+ Response 201 (application/json; charset=utf-8)
Is there a way to specify the media type ((application/json; charset=utf-8)) once, globally, for every response? This would have cleaned the document a bit.

As far as I know, this is not a supported scenario. I suggest you to file an issue on API Blueprint repository on GitHub to eventually get this feature request evaluated!

Related

How to do a REST POST with Grafana AJAX panel?

I have a SpringBoot API with a POST end-point.
Trying to make a call to end-point from Grafana AJAX panel
It seems to be hitting the end-point but error occurs complaining about missing body.
error: "Bad Request" message: "Required request body is missing: public org.springframework.http.ResponseEntity status: 400
But the request has indeed a body.
Have been looking for possible POST examples for hrs now but no joy, e.g.
https://community.grafana.com/t/using-ajax-plugin-to-make-rest-call/6674
Any tips or solutions would be much appreciated.
Asked this same question on Grafana support forum.
Turns out the plugin/panel in question does not support POST with body.
Indeed, it looks like POST JSON data to backend is not currently supported. There seem to be two related issues here:
https://github.com/ryantxu/ajax-panel/issues/48
https://github.com/ryantxu/ajax-panel/issues/13
You're welcome to share your thoughts there, it looks like this feature request has been added as a future enhancement but I am not sure when that work will be completed. In the meantime, you may need to forego using the AJAX Plugin.
So it's basically useless as my backend API end-point requires a body.
try the new JSON API plugin
https://grafana.com/grafana/plugins/marcusolsson-json-datasource/?tab=changelog
or AjaxPanel plugin for more control

How Should I Make Spring Boot Rest API's Return Response in Client Requested Formate

I have Spring boot Rest APIS, but i want make those APIS Response as per the Client Requested Format.
For Instance :
Rest APIS Return Response By default In Json format. But Client Want to in XML formate or any other formate.
In the above situation how can i make my APIS dynamically Retunr the Response as per the Client requested format.
can any tell how can i do this.
Thanks in advance.
What you are talking about is Content Negotiation - Here's a Baeldung article that describes how you might use Jackson libraries to handle both XML and JSON data,
https://www.baeldung.com/spring-mvc-content-negotiation-json-xml
You need to devise a content negotiation strategy - very often, that is the use of the Accept header. Your API then has to respect this header and return the appropriate content, which might mean your API contracts having certain attributes to allow it to easily serialize to JSON/XML.
The article linked above links to a github repo that shows how this might be achieved - https://github.com/eugenp/tutorials/tree/master/spring-mvc-basics

Why are GraphQL queries POST requests even when we are trying to fetch data and not update/submit new data?

I am using Postman to fetch data from my server and when I use a REST call it is a GET request but when I use a GraphQL API call, it needs to be a POST request. Why is it so?
The GraphQL spec is itself transport-agnostic, however the convention adopted by the community has been to utilize POST requests. As pointed out in the comments, some libraries support GET requests. However, when doing so, the query has to be sent as a URL query parameter since GET requests can't have bodies. This can be problematic with bigger queries since you can easily hit a 414 URI Too Long status on certain servers.
The best practice is to always utilize POST requests with a application/json Content-Type.

ServiceNow Scripted REST API GET with Body

I setup a GET scripted rest API. However, when I try to send a GET request with a body, ServiceNow (before it hits my code) complains that GET is not allowed to have a body.
Is there a way to disable this restriction? For now as a temporary workaround, I converted the request into a POST. However, this request does not change any state, so I believe it should be a GET. The request only searches for existing items.
GET is used without body, any configuration of a GET is in the URL and header. A query URL looks like this:
https://instance.service-now.com/api/now/table/problem?sysparm_query=active=true^ORDERBYnumber^ORDERBYDESCcategory&sysparm_limit=1
See the documentation here:
https://developer.servicenow.com/app.do#!/rest_api_doc?v=madrid&id=r_TableAPI-GET
Generally it's OK to use a POST to get data, graphQL does this for example, but i think SNOW is configured for GETs only.

API Blueprint - Avoid repeating authorization blocks

In API Blueprint, how do I avoid using the same request Authorization header block over and over for every endpoint?
+ Request (application/json)
+ Headers
Authorization: Bearer jsonWebToken
Is there a way to template this in a data structure perhaps?
Unfortunately API Blueprint has not such feature (yet)
On the other hand, I can tell you that authentication\authorisation framework is being worked - so it's possible that in a not so far future this issue will be solved for you.
Cheers!
Vincenzo answer is correct. The issue planned to address this is Authentication and MSON Parameters and Headers.
In the mean time. One work-around would be to use Hercule to split your blueprint into multiple parts and transclude the auth headers.

Resources