I want to add api to my wt-application for example:
1. I send request to wt-app:
2. I want to get response in json array (simple text without wt js code and html)
I did it using WtResource but i have problem when there are a lot of request and big json data.
1. Client1 -> send request 1 and wait for response (json data).
- Client2 -> send request 2 and wait for response (json data).
- Client1 -> got response.
- Client2 -> got response.
Client2 is waiting for response until first request will be finished.
Is there way to do it asynchronously?
Updated by Koen Deforche over 10 years ago
- Status changed from New to Feedback
There are several aspects to this.
First, you should probably deploy a resource for a public "api" (i.e. web services), as a global (static) resource, which is then not specific to a session.
Secondly, for both static (global) and dynamic (session specific) resources, Wt will not serialize access (not in the built-in httpd and not in Wt itself, not even when requesting resources from the same session). So the behavior you observer does not make sense, unless:
- somewhere in your code locking is being done to access the "json" data ?
- or, you are actually not using a multi-threaded build or are only using a single thread ?
- we've got a bug ?
Finally, if you are planning to transmit big resources, you should consider using response continuations, which allows transmission of a big response in chunks, freeing the thread and avoiding large memory allocations.