Websocket vs REST when sending data to server

Here’s a summary of the tradeoffs I’m aware of. Reasons to use webSocket: You need/want server-push of data. You are sending lots of small pieces of data from client to server and doing it very regularly. Using webSocket has significantly less overhead per transmission. Reasons to use REST: You want to use server-side frameworks or … Read more

HTTP PATCH support in browsers

HTTP/1.1 did not define the PATCH method. HTTP/1.1 does leave itself open for clients and/or servers to add new methods. RFC 5789 defined the conventions for using the PATCH method. The method defined within a HTTP request is nothing more than a string. Browsers should allow JavaScript to use whatever HTTP method it wants in … Read more

Flutter fetched Japanese character from server decoded wrong

If you look in postman, you will probably see that the Content-Type http header sent by the server is missing the encoding tag. This causes the Dart http client to decode the body as Latin-1 instead of utf-8. There’s a simple workaround: http.Response response = await http.get(‘SOME URL’,headers: {‘Content-Type’: ‘application/json’}); List<dynamic> responseJson = json.decode(utf8.decode(response.bodyBytes));

How do I get the body of a web request that returned 400 Bad Request from Invoke-RestMethod

There is a known issue with PowerShell Invoke-WebRequest and Invoke-RestMethod where the shell eats the response body when the status code is an error (4xx or 5xx). Sounds like the JSON content you are looking for is evaporating in just this manner. You can fetch the response body in your catch block using $_.Exception.Response.GetResponseStream() try … Read more

What is the difference between a HTTP-Get and HTTP-POST and why is HTTP-POST weaker in terms of security

In an HTTP GET request, key/value pairs are specified in the URL: http://server/something?value1=foo&value2=bar. In an HTTP POST request, key/value pairs are sent as part of the HTTP request after the headers. For example: POST /something HTTP/1.1 Host: server Content-Length: 21 Content-Type: application/x-www-form-urlencoded value1=foo&value2=bar It’s hard to really describe one as being more or less secure … Read more

When is it appropriate to respond with a HTTP 412 error?

If you look at RFC 2616 you’ll see a number of request headers that can be used to apply conditions to a request: If-Match If-Modified-Since If-None-Match If-Range If-Unmodified-Since These headers contain ‘preconditions’, allowing the client to tell the server to only complete the request if certain conditions are met. For example, you use a PUT … Read more

Restful way for deleting a bunch of items

One option is to create a delete “transaction”. So you POST to something like http://example.com/resources/deletes a new resource consisting of a list of resources to be deleted. Then in your application you just do the delete. When you do the post you should return a location of your created transaction e.g., http://example.com/resources/deletes/DF4XY7. A GET on … Read more