Mapping multiple values for x-amazon-apigateway-integration.requestParameters for a single key? - aws-api-gateway

I'm trying to create a new API on Amazon API gateway but for my use-case I want to concatenate 2 values for a single key in request parameters. How can we specify multiple values for a single key in integration.requestParameters?
This is what I'm trying to achieve but the syntax is not correct and it's giving me error:
For one to one mapping we use something like this
integration.request.querystring.start: "method.request.querystring.oauth_code"
Documentation link

I was able to solve it by following instructions in this Stackoverflow Answer.
Basically you need to add multiple parameters in the endpoint URL itself in the integration request, make sure that you are accepting those parameters as URL Path Parameters in the Integration Request.

Related

Routing incoming request

I am trying to create a simple API using Go that performs certain operations depending on the data provided.
I was planning to provide JSON data to this API and get details from it for further use.
Since I was trying to provide JSON data I created the routing using gorilla/mux as below:
router.HandleFunc("/msa/dom/perform-factory-reset?json={jsonData}", CallGet)
log.Fatal(http.ListenAndServe(":8080", router))
But while trying to hit the endpoint http://localhost:8080/msa/dom/perform-factory-reset?json={"vrf":"ds","ip":"45","mac":"452","method":"gfd"} I am getting 404 page not found error.
Hence I tried to change the implementation such that new routing is done as:
router.HandleFunc("/msa/dom/perform-factory-reset/json={jsonData}", CallGet)
This works absolutely fine and I am able to perform desired tasks. Could someone tell me why this is happening?
Is the router gorilla/mux? If so, you cannot add query parameters to path like that. You have to:
router.Path("/msa/dom/perform-factory-reset").
Queries("json","{jsonData}").HandlerFunc(CallGet)
If it is some other router, then you still probably have to register path without the query parameters, and then get the query parameter values in the handler from the request.

Is there a way to prevent Spring Cloud Gateway from reordering query parameters?

Spring Cloud Gateway appears to be reordering my query parameters to put duplicate parameters together.
I'm trying to route some requests to one of our end points to a third party system. These requests include some query parameters that need to be in a specific order (including some duplicate parameters), or the third party system returns a 500 error, but upon receiving the initial request with the parameters in the proper order, the Spring Cloud Gateway reorders these parameters to put the duplicates together by the first instance of the parameter.
Example:
http://some-url.com/a/path/here?foo=bar&anotherParam=paramValue2&aThirdParam=paramValue3&foo=bar
Becomes:
http://some-url.com/a/path/here?foo=bar&foo=bar&anotherParam=paramValue2&aThirdParam=paramValue3
Where the last parameter was moved to be by the first parameter because they had the same name.
The actual request output I need is for the query parameters to be passed through without change.
The issue lays in the UriComponentsBuilder which is used in RouteToRequestFilter.
UriComponentsBuilder.fromUri(uri) is going to build up a map of query params. Because this is a LinkedMultiValueMap you see the reordering of the used query params.
Note that RFC3986 contains the following
The query component contains non-hierarchical data that, along with data in the path component (Section 3.3), serves to identify a resource within the scope of the URI’s scheme and naming authority (if any).
Therefor I don’t think there needs to be a fix in Spring Cloud Gateway.
In order to fix this in your gateway, you'll need to add a custom filter which kicks in after the RouteToRequestFilter by setting the order to RouteToRequestUrlFilter.ROUTE_TO_URL_FILTER_ORDER + 1.
Take a look at the RouteToRequestUrlFilter how the exchange is adapted to go to the downstream URI.
Hope that helps! :)

Include multiple query parameters in HCM cloud rest Get call

I have an hcm cloud instance. I'm working on the rest api which are provided by the cloud.
I want to get an employee by matching both PersonNumber as well as DateOfBirth.
But whatever I tried based on the first parameter, I'm getting the output. Second is not even checked.
Can anyone help?
This is the rest url I'm using
https://host:port/hcmCoreApi/resources/11.12.1.0/emps/?q=DateOfBirth=1991-09-19&PersonNumber=240
For passing multiple search items in a query parameter in a rest call, the structure should be as following
https://host:port/hcmCoreApi/resources/11.12.1.0/emps/?q=DateOfBirth='1991-09-19'&PersonNumber=240
Basically quotes '' are required around String inputs and integer can be passed directly.

Modify Rest POST request behavior with query String

I have a resource which basically represents a number. I have two possible updates for this number: Set the number to a specific value or add a value to it. Now I'm confused if I can use the query string part of the URL to specify the desired behavior.
Something like this:
/resource/{id}/?mode=add
/resource/{id}/?mode=set
Or is there an alternative way two represent to update strategies for a rest resource?
An Alternative would be to extend the request body with this information but this since strange, since the request data should contain the data and not "meta information" for the request itself - as far as I understand REST apis.
The project is an ordinary angularjs (client) and java (server) project.

what is best option to pass parameters in REST api - POST type of method?

I am designing a REST api for creating a resource using POST method.
This create call accepts 4 parameters which are mandatory but not logically related to each other.
So I have two options to accept these 4 input parameters as -
Part of request as json object
OR
In the form of query parameters as (POST /api/someresource?param1=value1&param2=value2)
which option is most suitable?
Is there any guideline which suggests to choose one among above two methods based on the fact -
that these are mandatory parameters so we should not use query parameters?
these are not logically related but just a input to create a resource; so we can use query parameters?
/api/someresource?param1=value1&param2=value2 is likely a GET request and not POST request.
If your request changes a state on the server then use POST. If its only a read operation use GET.