I'm trying to call my azure proxy function with query string parameters.
I don't want to pass my params as route parameters, I want to do it with query string params as to not break my current contract.
My url is as follows https:/<mrUrl>.net/api/address-suggestions
I then have some static request overrides parameters that work fine.
Lastly I call the api as https:/<mrUrl>.net/api/address-suggestions?limit=10&query=main
In my proxies.json I have
"requestOverrides": {
"backend.request.method": "get",
"backend.request.querystring.api-version": "1.0",
"backend.request.querystring.countrySet": "US",
"backend.request.querystring.typeahead": "true",
"backend.request.querystring.query": "{query}",
"backend.request.querystring.limit": "{limit}"
}
That seems to be the only way to do what I want, but my response is always "query parameter is missing or empty" (note if I hard code the query in the JSON it works). Am I to assume there is no support for send query string params and only support for route params?
I found it for anyone looking. Use request.querystring.<yourQuerystringName>
Related
Suppose I have a REST endpoint like this :
http://server/users/query
And I have parameters in my query : age, city, country
I want to do a GET request with those parameters.
Should I better pass the parameters in the url ? Or put something like this in the payload of my GET request.
"query": {
"age": "something",
"city": "something",
"country": "something"
}
On my understanding, you have a collection of users and you want to get a representation of it. You should consider query parameters to filter your collection, as following:
http://[host]/api/users?age=something&city=something&country=something
And avoid GET requests with a payload. See the quote from the RFC 7231:
A payload within a GET request message has no defined semantics;
sending a payload body on a GET request might cause some existing
implementations to reject the request.
From MDN: GET requests (typically) don't have bodies so use the query parameters or the path.
If you are making requests to a server you should instead read the documentation of it's API.
I have created a web api with search option. For checking the api, i have used Postman tool in that i have provided symbols like "+", "#" for search. It is not recognized by the Web api Get method parameter.
From Postman Get Method() ->
http://localhost:60670/api/home?query=#
"query" is the parameter for search, in that i have given "+" or "#" keyword.
public IActionResult Get(string query)
But from the code it is not recognized by the Get method and "query" parameter is showing "null".
Help on this please!
few ways to do it:
1- encode your parameters : + --> %2B and # --> %23 (and any other special character) SEE : http://www.degraeve.com/reference/specialcharacters.php
2- send via POST instead of GET (I prefer this)
Encode your parameters:
original path = \Documents\FDS_D7U_C180175P+001005.pdf
encode path = %5C%20Documents%5CFDS_D7U_C180175P%2B001005.pdf
Enter the encoded path on the postman.
click on send.
Can we pass a SqlQuerySpec object as a parameter to stored procedure in Document Db? I think this gives us flexibility to send parameterized SQL text and parameters to procedure. If this is not possible, I would like to know if it is possible to access the complete SQL from the SqlQuerySpec.
Thank you,
Soma.
The server-side API takes the same JSON string as the REST and node.js APIs. The SqlQuerySpec type for the .NET SDK actually translates to this before sending it up when doing a regular query.
So, here are two ways you can compose the parameterized query from within your stored procedure.
In the package of parameters that you send to your stored procedure, include a JSON string like this:
'''
{
"query": "SELECT * FROM books b WHERE (b.Author.Name = #name)",
"parameters": [
{"name": "#name", "value": "Herman Melville"}
]
}
'''
You may be able to pass the string directly into a call to Collection.queryDocuments() but you may have to do JSON.parse(<your string>) before calling Collection.queryDocuments()
If you know the shape of your query is going to be the same for every call to this stored procedure, then you can send each parameter for your query in as a parameter for the stored procedure. You then have to compose the filterQuery object in the JavaScript of your stored procedure.
I've created a Swagger (on nodejs/express) test API with this specification (only relevant part):
...
parameters:
- name: name
in: query
required: true
type: string
...
But I can call the url with empty paramter, for example
http://localhost/test?name=
And it works without any problem, throws no exception or any other sign. Why?
If I make a similar call from the terminal via curl or via postman, it works as well. I parsed the query from the request object and found that in this case, the query parameter is interpreted as an empty string.
Making the call via SwaggerUI is different though, as the UI will actually not make the call UNLESS the query field has a value.
Try doing console.log(req.query); in your handler. You will probably see {name: ''}. Which is legitimate, just that the value of name is an empty string.
Look at JSON4 here: Representing null in JSON. So name IS defined, but it's empty.
You will probably need to do a check for empty string values.
I hope this helps!
Scenario:
Consider the following code:
var querystring = require('querystring');
var ParamsWithValue = querystring.parse(req._url.query);
Then I am able to read any query string's value.
E.g: If requested string is http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324
I can get the values of query string with codes ParamsWithValue.UID & ParamsWithValue.FacebookID respectively.
Issue: I am able to get the values of any number of parameters passed in the same way described above. But for second time onwards I am getting the following error in response on browser.
Error:
{"code":"InternalError","message":"Cannot read property 'query' of undefined"}
Question: What is wrong in the approach to read the query string from the URL.
Note: I don't want to use any frameworks to parse it. I am trying to depend on built-in modules only.
Update: It responds correctly when the value of any of the parameter is changed. But if the same values requested again from even different browser it throws same error.
I think you need req.url rather than req._url.
req.url is a string, if you want a URI instance use require('url').parse(req.url)
So, you should finally have:
var ParamsWithValue = querystring.parse(require('url').parse(req.url).query);
Edit: I corrected a typo in point 1, the last req.url -> req._url