Steel Roses

Standing on her desk There was a rose made of steel The day when she left It was the only thing she wanted to keep But there wasn’t room in her backpack It was a gift from her husband Who she was…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Introducing HTTP

Modern Systems Programming with Scala Native — Pragmatic Programmers (31 / 92)

👈 Testing Network Code with Netcat | TOC | Implementing HTTP 👉

In the last part of this chapter, we’re going to implement a usable subset of the Hypertext Transfer Protocol (HTTP). HTTP is indisputably the most important application protocol on the internet. Not only does it power the websites we use every day, but it’s rapidly becoming the universal protocol for all kinds of programs to request data from one another, via so-called RESTful APIs.

What does HTTP provide that TCP doesn’t? First, it defines a predictable request/response workflow, with well-defined message boundaries. Second, every request must refer to a specific resource, or object, named by a Uniform Resource Identifier, or URI. Third, each request must use one of eight methods on the resource, such as GET, POST, PUT, or DELETE, with well-defined semantics. Finally, HTTP transmits all of the above metadata in a message header, but allows any data format to be used for the content of either the request or the response — not just HTML or JSON!

Even though HTTP was originally designed only to deliver hypertext documents to web browsers, its generic and broadly supported capabilities have made it an essential block for all sorts of distributed systems and applications.

The standards body that governs the web, the W3C,[21] continues to promulgate extensions of the basic protocol, and even the giant tech firms that build web browsers can struggle to implement all of the standards correctly. But the core of HTTP is surprisingly simple and straightforward to implement.

An HTTP message contains either a request line or a status line, line-delimited headers, and optionally a body. The newlines are in the carriage-return line-feed style, which is written like \r\n in Scala and C strings. There is a single empty line after the last header. To see this in practice, let’s make a simple request. Instead of netcat, we’ll use the command-line utility curl:

Add a comment

Related posts:

Good Economics for Nigeria

When taxes are properly administered, it can help solve economic inequalities. The idea of paying taxes in Nigeria is dead to us.

Passing Arguments

Crystal is for Ruby programmers who want more performance, or for developers who enjoy working in a high-level scripting environment. Crystal combines native execution speed and concurrency with Ruby-like syntax, so you will feel right at home. This book, the first available on Crystal, shows you how to write applications that h

Some Days I Have Nothing to Say

This happens to me a lot, but I still try to put something out because I’m teaching myself to better create and write content consistently. It’s a long journey that demands my everyday dedication in…