Add custom static header information in response through Mashery - mashery

I am new to Mashery and just wanted to know if it is possible in Mashery to add custom static header information in response to a call and how?
If yes, then is it possible to make this header information enrichment conditional based upon the success or error HTTP code received from the target API?
I think if it is possible, then it should be possible by using the "Call Transformation" or "More Settings" links but I can't find the option to add a header (but I can find the drop header option in "More Settings")

It is possible to add custom static header in Mashery using the adapter 'com.mashery.proxy.core.add-headers-processor'.
Below configuration will add the header 'headername' in the request processed from mashery.
Processing Adapter = com.mashery.proxy.core.add-headers-processor
Perform Pre-processing = Enabled
Data to make available for pre-processing = headername:testvalue.
I am not aware of the possibility to add this header conditionally.

Related

"Client Error" message when trying to implement an Rest API View

I'm creating an API with Drupal to serve a angular application. The problem is, when I create the view with Rest export and try to access it (via browser or postman), it gaves me an "Client error" message (and nothing more).
I'm using drupal-8.7.6, running with PHP7.3, mysql and apache 2. But I've tried at nginx also and the error appeared again.
To reproduce it, just add some contents, enable the Restful web services, jsonm hal and create a view that exports rest data.
I expect to access the information via GET request (using browser, postman or any other way)
Go to your View
Go to Format
Click on Settings beside Serializer
Finally check Json option and save.
You are done :)
find out what was happening
I was not specificating the format of output, so Drupal was searching for an html to serve. To workaround this, just add to url: ?_format=json, for example, if my view route is "/articles", it will be: http://drupal.dev/articles?_format=json
Go to the rest exports view, click on format setting and click accepted request format to json.

Using mashape api in sapui5

I'm fairly new to sapui5 and I'm trying to use the Hearthstone API in order to show a list of cards.
I've registered in the page and I've obtained the X-Mashape-Key which I'm using to try to connect to the API.
For this, I've created a destination with the following information:
Besides this, I've created a view and its corresponding controller with the onInit function, with the following code:
Being the sUrl: /hsApi/cards and oHeaders:
var oHeaders = {
"X-Mashape-Key": "key"
};
The result that I obtain is the following one:
Request is failing stating that I'm not authorized to request the information, even though that doing the same request in PostMan I'm obtaining the information.
Most likely, this is caused by something really obvious but I'm not able to see it.
Could you try adding the following property to your destination? I am not sure what this property does exactly, but maybe you need it to allow this destination to be used in your WebIDE. Also try changing your "True" and "TRUE" to lowercase "true".
But I think you don't need any "Additional property" at all. Can't hurt to try it without them aswell.
Please keep in mind that you need to restart your WebIDE everytime you change something in your destinations as those are loaded statically every time the WebIDE loaded.

Attask- how to know that whether particular custom form is selected in the task or not

I want to search only those task from the project, which has a particular custom form (though not selected any field).
attask/api/task/5775...?fields=parameterValues,category
This returns only first custom form(category) object selected in the task and not all the custom forms..
I want to find all those task which contains particular categoryID..
Attask/api/ task/search?categoryID= 46785335&fields=parameterValues
It doesn't return me response when custom form selected after another custom form..
Since multiple custom forms is a new feature it is still only in earlyAccess this has not been released to the current API. You can however do this using the unsupported API.
the following will do what you are wanting.
GET attask/api-unsupported/task/search?objectCategoriesMM:ID=55a4232e005dc2668af39a4f24a4db40
This will search all forms not just the primary(first) form

Breeze EFContextProvider per request and based on parameter?

I have a multi-tenant app in which user can select "current company" after they log in.
There is a DB per company but the model is the same, the workflow is the same, and the controller actions are same....The user can switch companies while being logged in and all actions need to be 'directed' to proper DB.
I know it is possible to customize context creation in EFContextProvider<T> by overriding CreateContext() but how do I pass the extra info (parameter, e.g. CompanyId) that would allow me to create context with correct connection string?
Is this possible?
I find the easiest way is to include the tenant id in a custom HTTP header.
Because the tenant id changes during the session, you probably want to create a custom Breeze ajax adapter (wrap the one you're using now) that sets this header dynamically during its implementation of the ajax method.
On the server you fish the header out of the request.
MAKE SURE YOU ARE VALIDATING USER AND HEADER ON THE SERVER

Other RESTful actions on a resource

Lets say I have resource representing images
PUT /images/[id] with path -> going to create me a new image resource if already present updates my resource
POST /images/[id] -> to change or update a resource Ex., image name
DELETE /images/[id] -> this will delete my resource
GET /images/[id] -> gets me the image details
Now the actual question. what if I need to add additional actions to the images ?. Lets say the image resource will respond to a red eye reduction action or any other like crop, resize
So how these action are considered and how this should be called in restful interface ?
/images/[id]/remove_redeye
/images/[id]/crop
/images/[id]/resize
Is the above calls valid in restful interface ? I am confused about what should these action should be considered(PUT POST)?
"Remove redeye", "crop", and "resize" all sound like actions which "change or update a resource." They would belong in a PUT action. (I think you mixed up PUT and POST in your question, refer to the verbs listed at w3c.)
How you convey the nature of the action depends on what's being POSTed. For example, if we were talking about a form sitting on top of a database record, the POST would simply be the data for that record. It wouldn't be necessary to specify which fields are being changed because the whole object is being POSTed in its new state.
Is the whole object being POSTed in its new state in this case? Or does the object live only server-side and the interface is just sending a request for some kind of action? It sounds like the latter to me, based on the information provided.
In that case you can include in the POST some more information about the action. Keep in mind that a POST can contain key/value pairs in its data and/or a larger and more complex POST body. This body can contain XML, for example, specifying a lot more information for the server to use in processing the request. Maybe something like this:
<image id="123">
<resize>
<width>200</width>
<height>200</height>
</resize>
</image>
This could even allow multiple actions within the same request, allowing the user to try various things client-side before committing them all in a single unit of work server-side. How you'd process that or if it's even applicable in this case is up to you, of course.
PUT /images/[id] means to add a new resource or to fully replace an existing one.
POST means to create (/images) or to modify a resource (/images/[id]). If you create a resource, the server may return that resource for you.
For several modifying actions on the same resource (POST), I tend to use a custom header to define the kind of modification. In this case your resources
/images/[id]/remove_redeye
/images/[id]/crop
/images/[id]/resize
would translate to:
POST /images/[id] HTTP/1.1
X-RESTAction [remove_redeye|crop|resize]