Some web design questions.
Combine POST with GET?
When user clicks a button, I need to send one POST to submit a form, then need to GET a json object to replace some DOM fields. Should I combine them into one request so save one round trip time?
Multiple GET json request?
When user clicks a button, I need to GET 3 or 4 json object. Should I send 3 or 4 GET request, or just one and combine the json into one large json at back-end?
So basically, I'm not sure which is heavier: round trip time VS a little complexed back-end and front-end logic.
Any comment is welcome!
if i understood your question right...you have a dependency on your get requests...that is to say the second get depends on the first...if that is the case, obviously you need to take consecutive get operations...however, if that is not the case that is if you know the order of get request and the response won't be affected by local conditions...then i suggest you do post/get operations on server side...trigger the first one an let the server handle the rest and get the result...
of course you would not want users do multiple get requests for one simple operation...
Related
I have prepared a simple demo with react-router-dom 6 and react query.
I have a couple of routes and a fetch call that takes place on the first route (Home).
What I want to achieve is navigating to the About page or any other page and do not perform another request for a certain time period (maybe never again) but if I refresh the page I want to be able to re trigger the request to get the data.
I have tried using staleTime when but if I refresh the page I get no results, just a blank page. refreshInterval works on refresh but does not keep the data when I change routes.
I have also tried this pattern in this article but still I don't get the job done.
Probably it may be that something I don't understand but the question is how do I avoid making the same request over and over again, perfrm it only once but still being able to get the data if I refresh the page when navigating between different routes.
Demo
The solution to the problem came from one of the maintainers on the official github repo eventually and is related to adding placeholderData as an empty array instead of initialData and setting staleTime to Infinity in my case as I only want to perform the request once.
Setting placeholderData gives you the opportunity to show some dummy data normally until you fetch the real but in my case it seems to do the job. More to read regarding this at this source
const { isFetching, data: catImages } = useQuery({
queryKey: ["catImages"],
queryFn: getCatImages,
placeholderData: [],
staleTime: Infinity
});
I am new to jmeter, I am using jmeter to test e-commerce website.
I have manage to script one scenario, which is to add a product in basket and test the response time.
Now, I have observed that when i click Add button on UI, their are two requests which are getting POSTED.
for eg: stocks are updated.
As of now, I have copied the BODY from stock and pasted in jmeter sampler, but in future i may change the Sales order and update scenario, hence i want to store this Body data(Stock request which is updated) of this request dynamically, as it will change corresponding to sales order number im providing.
The problem is I am not able to store the BODY data dynamically(Only if i change the sales order here).
I know i can use pre processor in this matter, but could anyone help me with the code to get the BODY data from the request and store dynamically before sending the sample.
Basically I need a solution where I am just updating my sales order number and rest of the things will be taken care dynamically, in my case the POSTING of Body data for updating the STOCK.
Thank you in advance!
See basically, you're talking about Correlation. As I can understand from your concern. You need the data for the product added to the cart. Which needs data from prev request. This can be easily managed by generating two requests. Extracting from first and using that info for the second one. This will not involve any hardcoding and will work for you in an efficient manner.
Something like:
vars.put('bodyData', sampler.getQueryString())
should do the trick for you, if you put this code into a JSR223 PreProcessor and add this PreProcessor as a child of the HTTP Request sampler which body you need to store - you will be able to access the request body as ${bodyData} later on where required
In the above example:
vars - stands for JMeterVariables class instance
sampler - is for HTTPSamplerProxy
More information: Top 8 JMeter Java Classes You Should Be Using with Groovy
how can you manage and endless scroll using a real time server connection instead pooling each time the user come to the end of the list on nodejs and react?
thanks
User pagination on the server and manage that on the frontend, when you react to end of the list then try to fetch next page data and just assign that data to the reactive variable. it will bind on FE after that.
It can't be possible to fetch at once if the number of records are more like in 5-6K+ range. If you fetch at once then it will take more than one min maybe more than that, so until the user can't wait on the same page he might reload the page or leave the page. you need to call API each time for better UI/UX.
You can use directives like this.
Just focus on scroll if you get events like user reached the end of the list then simply print something like this (use opacity to get more focus)
if your API returns zero new data then just print something like this
Edit after comment:
No, you don't need to set an open connection to the server, just call an API when you reach the end of the list, like you calling only when you want to fetch more data from the server.
if you fetch the live data and you think that duplicates might be present then you can filter at the backend and remove duplicates via matching unique key. if that's not feasible then you can remove on FE also because you have less no of data on FE as compare to BE.
SO like if you're calling a third party API to get data, so first fetch all records if you can and store on your DB then call an API from your FE to get data from your own DB it will make a simple and fast rendering.
I have a view function that needs to gather multiple pieces of information in one call (it's a quick outbound call - the user answers and is to be immediately prompted for these data points), based on data pulled from a DB. What I'd like the view function to do is something like the following:
group_id = <get group id>
params = data_element_select_params.DataElementSelectParams(group_id=group_id)
data_elements = worker.select(params) # function I wrote which returns a list of objects, in this case objects called DataElements
vr = VoiceResponse()
say_msg = 'Enter {element}, then press star.'
for element in data_elements:
say_message = say_msg.format(element=element.name)
<Gather input with say_message and save it>
Can this be achieved without routing to the same URL over and over? I have not seen any other solution, and I'd rather not continually redirect to the same URL as we'll have to pull the list of elements from the DB again for each element.
Apologies if anything is unclear - please point it out and I'll clarify as quickly as I can.
Twilio developer evangelist here.
You can only use one <Gather> per TwiML document, so no, you can't ask multiple questions and take multiple inputs within the one webhook.
You will need to route to a URL that receives the input from each <Gather> and then asks the next question.
To avoid pulling all the elements from the DB every time, you could investigate saving the elements to the HTTP session and pulling them back out of there. Twilio is a well behaved HTTP client, so you can use things like cookies to store information about the current call/conversation.
I'm trying to create RestAPI. There are a lot of documents in DB, let's call those - goods. Each good have some property.
Client will get those, and show to user. Something like: ...api/goods?filter value here.
It looks pretty easy, but it is a wrong way to send all goods which satisfied the filter. I need to separate those, and send only needed part of data.
The first idea was create a separate route, that will obtain filter and amount documents on page, and return page count. So, front-end can build pagination and then, using handler on each pagination tab, makes requests to server, and get needed data.
I've created something like basic-example(code is not good but the main idea is):
https://github.com/Gordienko-RU/Tiny-pagination
But I thought there are another, better implementation of it. In 'best practice' there was some note about sending pagination in header, but I couldn't figure it out.
So, I want to know, what is the best way to send data by parts, but also give to client information needed to build pagination pannel(amount of pages).
I've found some handy method. There will be one route. Client do a request for data on first page, but answer contains not only needed data, it also will be an object with information about pagination. Something like:
data: [...],
pagination: {
pageCount: ...
etc.
}
Maybe not a 'best practice' but good enough)