How to use the DELETE request in Dispatch for Scala? - scala

I what to do is to make a DELETE request using dispatch. I know how to use it in POST and GET, but it seems that I can't find samples on how to use DELETE?

:/("www.scala-lang.org").DELETE
where :/ constructs new request. Some code snippets are available here, just to help you get started.

Related

Alternative to a Get request with a body: Post vs Put vs smth else

I know there are many questions like "How to use GET request with body" and in each of them it is recommended to use the verb POST instead. However, I do not really want to use it, because as a rule, POST requests do not guarantee idempotency. Maybe it's better to use PUT, which should guarantee idempotency? Or maybe some other one from the list of safe verbs?
Maybe it's better to use PUT, which should guarantee idempotency?
No. The problem is that PUT has semantics beyond the promise of being handled idempotently. Trying to hijack it as a query mechanism creates the opportunity for a mess, when general purpose components that understand HTTP assume that PUT means PUT.
POST has fewer constraints on its use. It is okay to use POST.
maybe some other one from the list of safe verbs?
There aren't many safe methods with request bodies, and you still have the potential problem of whether the implications of the method are too tightly constrained.
In late 2020, the HTTP-WG adopted a proposal for "GET with a body"; so eventually we should see a new method, probably called SEARCH, with semantics that will be useful for safe queries.

How to use Charles' rewrite tool only on certain methods?

I'm using Charles' Rewrite Tool to change 200 responses to 400 in order to test failing API calls. However, the rewrite is triggering on the Options request. I'd like to only have it trigger on the Get or Post requests and allow the Options requests through. Is this possible using Charles?
We were able to work around the issue by assuming that OPTIONS would always return an empty body.
The below Regex values will match for GET (because it has a response body) and not match for OPTIONS (because it doesn't have a response body).
\{[\S\s]*\}
or
\[[\S\s]*\]
I think Charles does not have this option, which is really a pitty, because it seems to be easy to implement and it would open the doors to the API world.
I would suggest you to ask Karl (the author and main developer) for this new feature at the contact section of the site.
We have this exact same need to mock API responses. Since the Rewrite tool doesn't support this feature, we have setup Breakpoints on the responses we want to mock, once the breakpoint is hit, we change the response to whatever we want. It works, but is less than ideal.
Unfortunately, Charles doesn't have this feature to filter out which the Request that has certain HTTP Method.
It's not a direct answer, but you can achieve with Scripting tool from Proxyman
function onResponse(context, url, request, response) {
// Update status Code
response.statusCode = 500;
// Done
return response;
}
Here is the Snippet Code that you can do with JS Code.
Disclaimer: I'm a creator of Proxyman. Since there are many people who struggle with this problem, hopefully, the Scripting tool can help you.
In Charles, you can use Breakpoints tools. FYR: https://tanaschita.com/20220307-manipulating-network-requests-and-responses-with-charles/.

Multiple request with AFNetworking

I'm trying to do multiple request in background to download many jsons and check data from them but I don't know how to use AFNetworking in that case.
I tried to do like Wiki explaings but when it's going to download the second file then the app breaks. I want to do all the process in background.
Thanks
AFNetworking will definitely handle this. We use it for exchanging data with a RESTful set of services. The things to keep in mind:
An operation (eg. AFHTTPRequestOperation) can only be used once.
An operation is asynchronous.
Put your operations in an NSOperationQueue, or use AFHTTPClient (suggested) to manage the operations for you.
When sending multiple requests, always assume that the responses will come back in a random sequence. There is no guarantee that you will get the responses in the same sequence as the requests.
Hope this helps to point you towards a solution to your problem. Without more detail in your question, it's difficult to give you a specific answer.
Check out AFHTTPClient's
enqueueBatchOfHTTPRequestOperations:progressBlock:completionBlock:, which lets you enqueue multiple requests operations at once with the added bonus of having a completion handler that is called when all of those requests have finished, as well as a block for tracking the progress. Also note, that every single operation can still have its own completion handler (useful if you have to process the results of a request, for example).
If you don't need to customize the request operation (and don't need individual completion blocks), you can also use enqueueBatchOfHTTPRequestOperationsWithRequests:progressBlock:completionBlock:, which allows you to pass an array of NSURLRequest directly without having to build the operations yourself.

Best way to send a series of HTTP requests with NSURLConnection

HTTP requests made with NSURLConnection are event driven. This makes things a little weird when you need to issue say three requests one after another, where each request uses information returned by the previous one.
I'm used to doing it like this:
response1 = request1();
response2 = request2(response1);
response3 = request3(response2);
But the only way I could find how to do this with NSURLConnection is to have connectionDidFinishLoading: make the next request. But when the number of sequential requests grows, this can get messy.
What's the idiomatic way to handle sequential HTTP requests with cocoa?
You could wrap the requests in an NSOperation and then define operation dependencies, so that each request must wait on its dependent requests before executing.
From the Apple Docs:
Dependencies are a convenient way to execute operations in a specific order. You can add and remove dependencies for an operation using the addDependency: and removeDependency: methods. By default, an operation object that has dependencies is not considered ready until all of its dependent operation objects have finished executing. Once the last dependent operation finishes, however, the operation object becomes ready and able to execute.
I would advise you using a 3rd party library called MKNetworkKit. It can handle the hard work for you, so you can focus on the key aspects of your application. You can find it here.
You can and should use NSOperation and NSOperationQueues.
A good tutorial can be found here: How To Use NSOperations And NSOperationQueues

modifying Zend_Soap_Server response

I want to modify the response that is sent when I am implementing a SOAP server using Zend_Soap_Server. I want to change the response that will be sent back because I am implementing the SOAP server for a client application that was written to work with another system but now I need to make it work with our system. The client application is expecting the XML response to be in a certain way. So what I want to do is that I dont want the handle method to put together its own XML response, I want to do it myself. Can this be done?
Thanks
I suspect there is some kind of output buffering trick you could use to do this, but a better solution might be to investigate the deeper cause of why the client is rejecting your XML and, in so doing, you may find a much more elegant solution.
For starters, you should probably read this very helpful article:
http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
You should then investigate Zend_Soap_AutoDiscover->setOperationBodyStyle() and Zend_Soap_AutoDiscover->setOperationBodyStyle() to see if changing the encoding style or binding style solves the problem.