In client-server communication, why server always respond (i.e.http Response) to user in HTML format? - client-server

In client-server communication, why server always respond (i.e. Http Response) to user in HTML format and not in any other format?

In HTTP Client-Server communication, it is possible to do a content-negotiation if the server supports different styles of responses like XML, JSON or TXT other than plain old HTTP responses. All that the client has to do is to send the desired format in Accept headers that is sent in the HTTP request. This is one of the core concepts of RESTful interface envisioned by Roy Fielding.

Related

GET request from server and client

Lets say we have other domain with API for get user by ID
web.com/id=5
My server localhost:1337 do request on this API...
request.get(...web.com/id=5...)
And gets response with all data.
But GET ajax request from client browser with same localhost:1337 dont work like that.
I hear about cross-origin but why my server dont care?
In general, APIs allow Cross Domain requests. They do this by using this header:
Access-Control-Allow-Origin: *
This header works for most cases, but there are additional headers used when dealing with custom headers, or non get/post requests.

Is it possible to specify HTTP headers in the URL?

I've got a (Spring) handler that I'd like users to be able to bookmark. As it's coded now, they get different formats (CSV, JSON) back based on the Accept header.
Would there be any way for users to specify the URL so that they can say what header they want? Or am I going to have to give URL-level parameter for the different formats?
Would there be any way for users to specify the URL so that they can say what header they want?
no there is no way to do that magically.
Or am I going to have to give URL-level parameter for the different formats? Yes this is valid
This is quoted from xml.com:
Server-driven negotiation. The service provider determines the right representation from prior knowledge of its clients or uses the information provided in HTTP headers like Accept, Accept-Charset, Accept-Encoding, Accept-Language, and User-Agent. The drawback of this approach is that the server may not have the best knowledge about what a client really wants.
Client-driven negotiation. A client initiates a request to a server. The server returns a list of available of representations. The client then selects the representation it wants and sends a second request to the server. The drawback is that a client needs to send two requests.
Proxy-driven negotiation. A client initiates a request to a server through a proxy. The proxy passes the request to the server and obtains a list of representations. The proxy selects one representation according to preferences set by the client and returns the representation back to the client.
URI-specified representation. A client specifies the representation it wants in the URI query string.

Compressing payload data in REST client call

Let say I have a bulk of text which needs to be pushed to a server thru REST api interface.
I also have a large volume of data/records to get pushed.
I am thinking that if we use compression technique then we can reduce the latency of data transfer.
Can this be done by including "Content-encoding' in my REST api request though the public API provided my the server did not specify CE option?
Edit
In particular I need to figure out how to do this using rest-client gem in ruby.
Yes the REST API allows the use of compression on the request and the response, using the standards defined by the HTTP 1.1 specification. And this is by using Accept-Encoding to tell the server what compression the client supports and the header Content-Encoding to describe the compression of the body. You may also check those links :
Enable HTTP Compression for Requests
JSON REST Service: Content-Encoding: gzip
WCF REST Compression

Multiple URL opening in MFC

I am trying to send simultaneous request for opening URL in OpenURL() in CInternetSession class. But After sending 2 URLS requests, no other request can be send without receiving the response from previously send requests. How can I send a large number of URL request to a server and later only i want to process the response. Please help if any other API is there for sending multiple URL request to a server and receiving the response later. I want to use in MFC windows
The HTTP 1.1 specification (RFC 2068) mandates the two-connection limit.
In this way, WinInet (CInternetSession built on top of it) limits connections per server (MSDN).
You could try to invoke SetOption and adjust INTERNET_OPTION_MAX_CONNS_PER_SERVER and
INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER values. (MSDN)
Something like this:
sess.SetOption(INTERNET_OPTION_MAX_CONNS_PER_SERVER, 8);
sess.SetOption(INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER, 8);

Can AJAX use protocols other than HTTP or HTTPS?

I wonder if AJAX can use protocols other than HTTP or HTTPS.
Ajax means XMLHttpRequest. Just as you don't have to use XML with XHR, you also don't have to use HTTP.
Despite its name, XMLHttpRequest can be used to retrieve any type of data, not just XML, and it supports protocols other than HTTP (including file and ftp).
From the W3C XMLHttpRequest spec (emphasis added):
The XMLHttpRequest object implements an interface exposed by a scripting engine that allows scripts to perform HTTP client functionality, such as submitting form data or loading data from a server. It is the ECMAScript HTTP API.
The name of the object is XMLHttpRequest for compatibility with the Web, though each component of this name is potentially misleading. First, the object supports any text based format, including XML. Second, it can be used to make requests over both HTTP and HTTPS (some implementations support protocols in addition to HTTP and HTTPS, but that functionality is not covered by this specification). Finally, it supports "requests" in a broad sense of the term as it pertains to HTTP; namely all activity involved with HTTP requests or responses for the defined HTTP methods.
The available protocols beyond HTTP and HTTPS are non-standardized, so they depend on the specific environment1 you're using. That is, all compliant XHR implementations must support HTTP and HTTPS, but are not required to support any other specific protocols. That means that you might find that Internet Explorer supports
1Such as, which version of which browser (Safari vs Firefox vs Chrome vs IE vs Opera vs...), or which server-side implementation (V8 vs Rhino vs...)
XMLHttpRequest (XHR) is an API available to web browser scripting languages such as JavaScript. It is used to send HTTP or HTTPS requests to a web server and load the server response data back into the script.
from wikipedia

Resources