From api response I have page and nextPage as String. There are total of 2 pages and page number is appended at the end of the request.
Sample request url is
.../listing/{page}. In my case since there are 2 pages request urls are (.../listing/1) and (.../listing/2). For first request (.../listing/1) I get 20 items and nextPage = 2 and for second request which is (.../listing/2) I get another array of items.
For second request there is no nextPage parameter, and I would like to send request to the API till there is no nextPage parameter with using pagination.
How can I build this logic?
Related
Is there a way for me to get the number of the process to which the page object belongs? I want to use puppeteer to get the loading error of a page resource, but I can't find the correspondence between the intercepted error request and the page object. I found that the _requestId of the intercepted request is combined using the process ID, so I want to get the process number of the process to which the page object belongs.
I have a Core 2.2 Web API project as my back-end for an Angular front-end. On one screen I allow the user to select x amount of records for processing from a data grid. Before the records can be processed I need to check the database to see if records exist in another table by passing a list of 3 fields (intelligent key) to my API. I put this list into an object array, do a Json.stringify on that object and send it to my API as a Get request. This works fine as long as I select 1-3 records. As soon as I select 4 or more records I get "Access to XMLHttpRequest at 'request url' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
My Cors policy indicates it should let anything through and I'm also confused by why 1-3 records works fine.
In my startup.cs -> ConfigureServices method I have the Cors policy defined like so:
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.WithOrigins("http://localhost:4200")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
In my Angular service I make this call which serializes by array (apiUrl is my url to call my API: https://localhost/api/controller)
getRecordsByIntelligentKey(intelligentKey: IntelligentKey[]): Observable<Record[]>{
const jsonObject = JSON.stringify(intelligentKey);
const url = `${apiUrl}/${jsonObject}`;
return this.http.get<Record[]>(url).pipe(
tap(_ => console.log('fetching records based on intelligent key')),
catchError(this.handleError('getRecordsByIntelligentKey', []))
);
}
In my controller GET action I deserialize my string. I mean I'd like to pass an object but I think I need to do a POST for that.
[HttpGet("{jsonObject}")]
public ActionResult<List<Commission>> GetByCustomerAndTerritoryManager(string jsonObject)
{
try
{
var intelligentKey = JsonConvert
.DeserializeObject<List<ThreeFields>>(jsonObject);
return _repo.GetRecordsByIntelligentKey(intelligentKey);
}
catch (Exception ex)
{
_logger.Error(ex, "Error retrieving records.");
throw;
}
}
Now my problem is the user could select 1000s of records. When I select over 1000 records I just get ERR_CONNECTION_RESET probably due to the querystring being way too long.
I'm thinking I need an object but everything I've researched seems to advise against doing that with a GET and using the POST request instead. Problem is, it's a restful API and I'm already using the POST request for the processing portion. I guess I could use PUT or DELETE but it just feels wrong. I'm going to wire up the PUT right after I post this question to see if it will work but ultimately I'd like to find the correct solution for this.
UPDATE: The PUT method works fine even with over 1000 records selected so I guess this will be my interim solution for now. I still feel like there's code smell and would love to use a GET but at least this allows me to proceed.
Opening https://www.coinome.com/exchange/data.json in browser shows a json,but while trying to fetch response by making a GET request,the returned response is in html format.
How to get JSON response instead of html response?
that's because the first time you perform the request to that url, the server returns an html form to check whether youare human or not.
Then after you compile and submit the form a cookie is returned.
You have to save that cookie and redo the request to the same url while putting the cookie in the request header in order to get the response in json format.
I am using angular 2 as front end frame work and node js in the back end, So I am trying to send image with a json object that contains some particular information about that image. So I am wondering , if it is safe to pass that json object in the URL.
No, it's not safe, as your JSON object might be very long, too long for a URL. You will need to send an AJAX request where your JSON will be a parameter. Example of asynchronous request sending a JSON object:
xhttp.open("POST", "ajax_test.asp", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("data=" + JSON.stringify(yourobject));
then, on the server you will have a POST parameter called data where you will have everything you need.
I want to call node red HTTP page, like node_red_url:1880/test and have a json formatted output back, like:
{"result": [{"Type": "Temp","Data": "30.0 C","id": "31"}]}
Data will be pulled from a MQTT node
is this possible?
Ive found a static page, but i cant to find out how to add dynamic data to it
https://cookbook.nodered.org/http/serve-json-content.html
Yes it's perfectly possible. You just have to realise that the MQTT delivery has to be totally separate from the HTTP request.
MQTT-in -> function node to store latest value in the context
HTTP In -> function node to retrieve value from context -> HTTP Response node