Open source tool for Rest API Adapter - rest

Is there any good open source framework for Rest API Adapter, API adapter use cases :
Maps the REST API source request body signature to target request body signature and source response body signature to target response body signature and which has to be configurable.
For Example :
Source API expects Json :
{
"name" : "testing name 1"
}
Target API expects Json
{
"name_t1" : "testing name 1"
}
the name and name_t1 has to be mapped to two rest APIs to function and similarly for mapping of response bodies from source to target. This is a simple example the source and target request API has nested multi-dimensional arrays.
Is there any good framework which does this job?
Regards
Kris

Related

API call in Response and another response types

How can I call API url (Fulfillment or Webhook as named by API.AI) from Watson conversation API Response.
I don't need to enter the full list of expected responses from the Response section.
I need to call an API with the understood JSON object to handle the response from the backend (fetch DB for example) and return the expected JSON to the user (requester).
Any advice?!
Not sure I understand your question, you cannot program within the Conversation service tooling to call out to other services etc, as part of a response or message.
These are the types of actions that the middleware or service layer part of your application should handle. Not to be recommended but you could program the client element of your application to process additional api calls.
You will find both on this forum, and in the IBM docs examples of the use of whats called "action" json elements that can be added to your conversation response payload. Thus along with the response output text ( or in place ) you add an "action" json element to the output and context json object that includes instructions to your middleware or client part of your application. i.e.
"output" : { "Text" : "Hi there" },
"action" " { "api_url" : "http://bluemixservice.ibm.com", "Task" : "insert", "data" : "User asked for an alarm at 5pm" },
"context" : { "conversation_id" : "asdada" }
Hope this helps.

Using Spring Cloud Contract Groovy DSL, how can I parameterize the response to include values from the request?

I am using Spring Cloud Contract to create stubs for a REST service so I can test with a REST client. I have the stub runner working within a Spring Boot application, and it all works as expected. The problem I am having is that I'd like to see elements of the requests in the responses, to better simulate the eventual behavior of the REST service. For example, in this contract, I'd like what is passed in the "code" field in the request to appear regurgitated in the response:
package contracts
org.springframework.cloud.contract.spec.Contract.make {
request {
method('POST')
url $("/resource")
body ([
code : $(client(regex('[a-zA-Z0-9]{5,32}')))
])
}
response {
status 200
body([
code: ???
])
}
}
Obviously the input "code" can be anything that matches the regular expression, and so the actual value is unknown until runtime. Is there anything i can put in place of "???" to return the code submitted in the request ? I tried accessing, for example:
request.body.serverValue['code']
but that value it seems is generated at compile time, perhaps to enable the auto-generation of tests in ContractVerifierTest.java under generated-test-sources.
Can this be done ? Is this an appropriate use of Spring Cloud Contract ?
Currently, it's not supported. We prefer an approach where you have simpler contracts. If you need in a response a value from the request just hard code both the request and the response parts of the contract.
You can, however, file an issue and we can try to think of something in the future releases.
UPDATE:
With version 1.1.0 that's already possible. Check out the docs for more info - http://cloud.spring.io/spring-cloud-static/spring-cloud-contract/1.1.0.RELEASE/#_referencing_request_from_response

Feature Request for Swift Perfect - RAML

As per http://perfect.org/feature-requests.html
I would like to request that RAML functionality be included out of the box.
I would like to see something like the following on the server for serving RAML documentation:
server.addRamlDocs(path: "/raml.raml", versionRaml: 1.0, versionApi: "v1", title: "Test API title")
This would add a route that when matched creates a full RAML file for all RAML routes.
RAML routes should probably be created in a similar fashion to MustachePageHandler but split into RamlDescriptionHandler, RamlValidateRequestHandler, RamlRequestHandler and RamlResponseHandler.
RamlDescriptionHandler
This should be responsible for:
Describing the request / response
Automatically creating documentation for the request (when server docs matched)
RamlValidateRequestHandler
Validating and type casting the request
This should then inject HTTPRequest.ramlRequestData and HTTPRequest.ramlRequestIsValid. This should require no action from the application developer.
RamlRequestHandler
Application logic to be coded by the developer, should check and use HTTPRequest.ramlRequestData and HTTPRequest.ramlRequestIsValid
Should set HTTPResponse.ramlStatus (HTTP Status Code) and HTTPResponse.ramlData
RamlResponseHandler
Should validate the response and send matching against RamlDescriptionHandler, no action from the application developer.

POST to GET Scenario, method body to query string parameter

I think I hit an AWS API Gateway scenario that doesn't appear to have a solution.
I am trying to create a json POST endpoint to validate an address against a USPS service.
The ultimate request looks like this:
http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="SECRET"><Address><Address1>101 Foo Lane</Address1></Address2><City>Somewhereville</City><State>CA</State><Zip5>90210</Zip5><Zip4></Zip4></Address></AddressValidateRequest>
The issue I'm having is I need to set the XML query string parameter based on my passed in method body, e.g.:
{
address: "101 Foo Lane",
city: "Somewhereville",
state: "CA",
zip: "90210"
}
It appears in the Integration Request, I can specify the "Mapped from", but I can't access the method body, only the method.request.{"path", "querystring" | "header"}.{param_name}
Also there doesn't appear for me to construct a param_name value in the Method Request setup from the incoming method body.
The XML to JSON response mapping is working great if I provide a hard coded XML query string, so I'm down to just the request mapping.
You can map the body to request parameter using method.request.body.JSONPath_EXPRESSION but you can't construct the request parameter using a template similar to what can be done for integration request body. All the available mappings are documented here - http://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html

Mapping Querystring Parameters to Resource Methods in JAX-RS

Amazon's web API uses a "query API" for non-CRUD operations by using a querystring parameter to specify the operation. I want to implement non-CRUD operations in a similar manner.
Is there any way to map a POST resource method using Jersey JAX-RS dependent on the value of a particular querystring parameter? For example I would like to do something like this:
#POST #Query(name="xaction", value="move")
public Response move(#QueryParam("source") String source, #QueryParam("dest") String dest)
{
...
}
#POST #Query(name="xaction", value="copy")
public Response copy(#QueryParam("source") String source, #QueryParam("dest") String dest)
{
...
}
In the above example I would expect a framework would dispatch to the appropriate method depending on the value of the "xaction" querystring parameter regardless of URI path. Unfortunately I do not have the luxury of using paths or methods to distinguish these operations. I am open to other library suggestions that are compatible with JAX-RS or custom implementations to resolve this.
REST is not Remote Procedure Call (RPC). Even if Amazon is publishing an API like this, it is still not RESTful.
JAX-RS does not provide a mapping you describe for good reasons. Every Resource must be uniquely identifiable by the URI which includes the full path and all query parameters. URI like you describe don't identify Resources but call procedures.
Ask yourself these questions:
What are your Resources?
Do actions on Resources easily map to HTTP verbs?
If not, can actions on Resources me modeled as Resources?
As example for 3., you could thing about a MoveResource and a CopyReource.
A JSON Representation of a MoveResource could look like this:
{
"source": "/path/to/source",
"dest": "/path/to/dest"
}
Creating such a MoveResource and thus triggering a move could be done by a POST to the collection Resource at /moves. This POST would return 201 Created with a Location header like /moves/42. A GET to this Resource could return the state of the MoveResource:
{
"source": "/path/to/source",
"dest": "/path/to/dest",
"status": "success"
}
The same could be done for a CopyResource.