REST Best Practices: Optimizing Content Retrieval With Conditional HTTP Requests

As promised in our previous article, this post will be about the ways to optimize the response time from a web service when a client needs to read a resource. We are going to achieve this by not reading information on a resource if it has not changed. This helps developers create faster web applications.

The Problem

Suppose you want to create a web service that reads information on a resource only when it has changed. For instance, think of an application that allows you to manage calls in a call center. This application lists all the calls in the system in a page and adds new calls to the list in real-time. Since calls can take more than a few minutes, a time-frame during which no changes occur, the application will reload the list only if new calls occur or a call is closed.

Making Conditional HTTP Requests

To solve the problem, the web service and the application communicate by passing conditional HTTP headers. Some of these headers, Last-Modified and Etag, are not new to you as you’ve already read about them in a previous article. In today’s article, we’ll be introducing two new ones, namely If-Modified-Since and If-None-Match.

So, if you want your web service to support conditional HTTP requests, you have to design it to return the Last-Modified and Etag conditional headers. Clients of the web service receive these headers and save them. At a later point, when clients make the same GET or HEAD HTTP requests and want to check if the information they have is still fresh, they must send the following headers to the web service:

  • If-Modified-Since with the value of the Last-Modified header as received in response to the initial request
  • If-None-Match with the value of the Etag header as received in response to the initial request

If the web service determines that a If-None-Match header was sent, then it compares its value to that of the ETag as saved internally. If the If-Unmodified-Since header is received, its value is compared to the date the representation was last modified. If the checks are false or if the client did not send these headers, the web service must return the Last-Modified and Etag headers to the client and a HTTP response with status 200 OK. If checks prove to be true, an HTTP response is returned with the 304 Not Modified status.

This method does not decrease the number of HTTP requests the client makes to the web service. It might reduce the load on the database and the response overhead, because in many cases it’s not needed to serve a response back, as nothing was changed since the last request. Reducing load on database might be a tricky subject, so we want to discuss this further in a next article – it actually matters a lot how you compute Etag and how you keep track of changes.

Making HTTP conditional requests enables the web server to improve its response time. Applications also save resources, since they are not required to reload the information if no changes occurred.

An Example

Let’s assume that the call center application above decouples its interface from its back-end. The interface is written in JavaScript and the only way it can communicate with the back-end is through a RESTful service. This means that, when it needs the list of calls, it makes a GET HTTP request to the web service. The application expects to receive the Last-Modified and Etag headers in the response received.

# First request that reads the list of calls
GET /call HTTP/1.1
Host: my.callcenter.com

...
# The web service responds with 200 OK and 
# a resource that contains the list of calls
HTTP/1.1 200 OK
Content-Type: application/json
Last-Modified: Sun, 13 Jun 2013 13:00:15 GMT
ETag: "cbd1956fb32c0275f1faccbb6fafff8f"
...

{ "call": [
	{"source": "3334444",
	 "sourceCallerName": "Marry Smith",
	 "destination": "2224444",
	 "destinationCallerName": "John Smith",
	 "answered":"9 Jun 2013 12:34:12"},
	{"source": "5554444",
	 "sourceCallerName": "John Doe",
	 "destination": "6664444",
	 "destinationCallerName": "Jane Smith",
	 "answered":"9 Jun 2013 13:00:12"},
 ]
}

As you can see, the web service returns the Last-Modifed and ETag headers. The second time the application wants to read the list of calls, it makes an HTTP request in which it includes the headers If-Modified-Since and IF-None-Match. The web service compares the values received in these headers with the ones known internally and, if nothing changed, it returns an HTTP response with a 304 Not Modified status.

# Second request to read the list of call
GET /call HTTP/1.1
Host: my.callcenter.com
If-Modified-Since: Sun, 13 Jun 2013 13:00:15 GMT
If-None-Match: "cbd1956fb32c0275f1faccbb6fafff8f"

...
# Nothing changed since the last time 
HTTP/1.1 304 Not Modified
Content-Type: application/json
Last-Modified: Sun, 13 Jun 2013 13:00:15 GMT
ETag: "cbd1956fb32c0275f1faccbb6fafff8f"

To sum up, this is the way you can save web service response time and create faster applications. In one of our future posts we’ll be discussing partial updates as requested by a reader, so keep reading our blog. :)

Wanna Be Our Product Wizard?

In one of our previous posts, we were introducing the VoipNow Team as one of the most complex teams at 4PSA. It handles marketing, sales, customer support, and product development for a product that has been on a continuous ascending curve. Since VoipNow has grown to be a very popular “child”, our team is in need of more people. We are now looking for Product Wizards, i.e. Clouders for whom VoipNow will hold no secrets and who will be able to decode any misunderstanding and solve any issue customers might experience while using it.

Why We Need Your Talent

Our support guys have specialized in solving complex technical problems, while the sales team is at its best when handling business inquiries. We are now looking for Clouders who fit right in the middle – enthusiastic Product Wizards who will provide Level 1 assistance to our customers.

_MG_1010

 
If you’re wondering how you will be able to know everything and anything about it, no worries. You will have the best support at hand. In no time, :) you will impress our customers with your prompt and useful replies by phone, e-mail, and via the ticketing system. You will also be a star in our Get Satisfaction community, where you will deliver smart solutions to users in need. Finally, you’ll determine what documentation can help customers better understand their system and you’ll assist our technical writers in producing it.

And because our team takes pride in running like a clockwork orange ;) you will work together with Level 2 Engineers, developers, and sales people to deliver the best customer experience possible.

What You Should Know

Our customers are extremely important to us and we want this to be reflected in every single form of interaction we have with them. So, before anything else, you should be an excellent communicator in written and verbal English as well as have good telephone manners and strong customer service skills. If you want to be successful in this job, you will also need basic Linux knowledge and good understanding of concepts such as IP, DNS, networking.

Last, but not least, the desire to learn and improve defines all VoipNow team members. If you share the same attitude, we can guarantee you’ll be making friends in no time.

Experience? You should have a 2+ year previous experience in a customer service environment, preferably dealing with international customers.

What We Offer

We’re offering you a spot in the team that lays behind the success of a product that is used and loved by people throughout the world. There is much you can learn from us, but most important there’s a lot we’ll be learning together while making VoipNow even better for our users. We know that there can’t be creativity without relaxation. That’s why we make a point of having fun with every chance we get. ;)

If this sounds just like you, drop us an email at jobs AT 4psa.com or simply apply online.

The Magic Of Seven – 7 Years Of VoipNow

From the dust of old centuries until today’s computer-driven and smartphone-glued society, seven has always been considered a magical number. Many believe in the power of seven, be they sorcerers or mathematicians, historians or, in the past decades, even psychologists. Seven days in the week, seven wonders of the world, seven primary colors, seven notes in the musical scale, seven ages of man, Miller’s law on human brain’s capacity of processing information, and the list can go on and on.

So, what makes this number so special? Depending on interest or vocation, you’ll get a different answer every time you ask this question. I’m no scientist, so my answer is not that complicated, yet it does have its touch of magic. :)

VoipNow was officially launched seven years ago! On May 30, 2006, 4PSA was the first company in the world to introduce a communication platform that enabled service providers to offer affordable VoIP services, a state-of-the-art substitute for traditional PBX boxes.

VoipNow_bday_2013

 

It has been a wonderful journey from day one, when the first idea of such a product popped into an architect’s mind. In the years that followed, it turned into a software used by millions of end-users all around the world and it will continue to do so as a platform for providing and using Unified Communications services.

In 2006, the market was still controlled by the giant telecoms. VoIP was considered cheap, low-quality, and insecure. Big, expensive boxes were the normal PBX that powered most offices. The world was not ready for a communications revolution, and yet VoipNow was exactly that! Then, step by step, after having invested a lot of effort in educating the market and as a result of the financial crisis that redefined budgets and forced changes on old, traditional communication flows, companies and individuals around the world started to grasp the huge benefits brought on by UC. That was exactly what service providers needed to embrace such services and start spreading the love. ;)

Before writing this article, I wanted to go back in time seven years ago and reminisce about that May 30 in 2006. I remembered the very first VoipNow order we received immediately after the product became available. Since then, thousands of service providers and millions of end-users have been using VoipNow.

On behalf of the entire 4PSA team, Thank You! Thank you for using VoipNow, for your help to continuously improve the product, for your feedback on new features and functionality, for running your business on VoipNow, and for putting your trust in our vision!

This is also a Big Thank You to All 4PSA Clouders that brought their contribution in the past and will continue to influence the development of VoipNow in the future, either as a member of the VoipNow Team or by being part of any other 4PSA team. It is also an invitation for future Clouders to come and join us in our wonderful journey.

Ever since we started 4PSA, our vision has been about making software that would help people improve their lives through technology. VoipNow has been carrying on this vision by enabling people to communicate better and more efficiently. The next step is extremely close and it will be our immense pleasure to share it with you.

Happy Birthday, VoipNow!

CSS Display And The Basic Box Model

This article aims at clearing up some of the misconceptions about the CSS display property and the way it affects the box model. It will only take into account the W3 specifications. To avoid blurring you with all sorts of details and exceptions, various browser inconsistencies will be swept and kept under the rug. The purpose is to give you a clear understanding of the matter, so that you shouldn’t be afraid of doing more than changing colors from a stylesheet picked up from who knows what source.

Block Or Inline?

HTML elements can be displayed in two very distinct ways: inline or block. There are many differences between them, but the most important is that inlines flow one after another horizontally, until they have reached the end of the line, at which point they continue to flow on the next line. Blocks on the other hand flow one after the another vertically, and each of them basically occupies an entire line. HTML shows flexibility in allowing elements to flow and this is one of its benefits, as you can insert content in the page at any point and the entire page will rearrange itself to accommodate the changes.

The term flow, or formatting context, refers to the space occupied by inlines or blocks. Each formatting context is responsible for the rendition of its components and it does so according to the principles described above:

  • An inline flow distributes its content in lines (useful if you want to display some text).
  • A block flow renders each element on a new line (useful for separating the document in sections, like paragraphs).

A block flow also permits a higher degree of control over the placement and size of the contained elements, which is why when creating the layout of a web page, most of the time you will interact with block elements.

The diagram below shows the difference between a block flow with 3 blocks and an inline flow with 3 inlines.

apps_robots

While there are two important ways in which HTML elements are displayed, the display property can take several values, each with its own particularities. Let’s consider the elements with display:inline-block, for example. Not only they participate in an inline formatting context, but they also share some of the characteristics of block elements on the inside (width, height etc). Elements with display:inline-block act as inline on the outside and as a block in the inside. The particularities of inline-block elements are discussed in the section below.

Breaking The Flow

There are two important rules about the display property that children of HTML elements have:

  • Children of an element are either all inline or all block.
  • Children of an inline element are all inline.

However, if these rules are always followed, then you might ask yourself: How come we can write stuff like a mix of inline (span) and block (div) elements as children of an inline element and they still get properly displayed? The answer is anonymous blocks! HTML is very flexible, meaning that it allows all sort of weird constructs and does its best to make them work.

Let’s review the following example:

<span id="inline-box">
    <span id="first-inline-child">Some text</span>
    <div id="block-child">I break the flow</div>
    <span id="second-inline-child">More text</span>
</span>

In this case, to help preserve the two constraints mentioned above, the browser creates 3 anonymous blocks (think of them as divs) that split the #inline-box span and its content. The first block contains the #inline-box span with the #first-inline-child span as the only child. The second block contains the #block-child div. The third block includes a continuation of the #inline-box span with the #second-inline-child span as the only child. With these anonymous blocks added, both constraints are met: each element has only inline or only block children and each inline element has only inline children.

The browser will interpret the above code in the following way:

<anonymous_block>
    <span id="inline-box">
        <span id="first-inline-child">Some text</span>
    </span>
</anonymous_block>
<anonymous_block>
     <div id="block-child">I break the flow</div>
</anonymous_block>
<anonymous_block>
    <span><!-- Continuation of span#outer -->
         <span id="second-inline-child">More text</span>
    </span>
</anonymous_block>

A keen eye would notice that the div is no longer contained by the #inline-box span. This might lead to some properties affecting the #inline-box span (such as background-color:red) behaving not exactly as expected.

break-the-flow-results

Breaking the flow can have unexpected consequences, so it is not recommended.

Blocks, Inlines, And The Box Model

Blocks and inlines are inherently different. It is not just a property that is toggled between these values; many other properties are affected by the display, the most important of which are probably those concerning the box model: width, height, padding, border, and margin. While they largely apply to both kinds of elements and have approximately the same meaning for both, the box model properties are calculated quite differently for inlines and blocks.

Here is the reference image from W3C regarding the box model:

3

There are a few problematic properties (float and positioning) that further alter the computations of the width, height and margins, but they are not subject of this article. It is recommended that you simply assume there are no floats in the document and all elements have position:static.

Replaced elements is yet another category of elements that might pose problems with regard to the box model. The content of such elements is replaced by an outside source and the rendering engine cannot decide their properties on its own. The three most common examples of replaced elements are img elements, iframes, and form elements. To give you a better idea, think of them as placeholders: when the document is rendered, these elements need outside help to be displayed. For example, instead of the img tag, the actual image resource is rendered. Replaced elements can be either inlines or blocks and they may or may not have intrinsic sizes (defined by the outside source – such as the width and the height of an image resource).

Here is how box model attributes are computed when they are set to auto:

  • Padding and borders always default to 0.
  • Margins default to 0, except for block or replaced block elements with a specified width. In such a case, the left and right margins are equal so that the width, left and right margins, paddings, and border add up to the width containing box (please see below).
  • Te width and height of replaced elements are intrinsic values, possibly adjusted to preserve the ratio, if one of them is not auto.
  • The width and height of non-replaced elements are computed as explained below.
Attribute Inline Block Inline-Block
width not applied available width* minimum of intrinsic value and available width*
height not applied from top margin edge of the first child to the bottom margin edge of the last child** from top margin edge of the first child to the bottom margin edge of the last child

 
*Available width is the value of the containing box width, minus the left and right paddings, borders, and margins. The containing box varies according to the position property. The containing box may be the content box of the parent (if the element is positioned static or relative), of the body (if positioned fixed), or of the closest ancestor with a position different than static (if positioned absolutely). This will be reiterated in a future article, when we’ll discuss about positioning.

**If block elements have overflow:visible, their height is computed as the distance between the top border edge of the first child and the bottom border edge of the last child.

Here is a short example to help you visualize the table above.

display

In all images, there is a green element with a blue and a pink child. The margins of each element are rendered with a lighter color. The width, height, and margins of the green element are set to auto, while the blue and pink elements have random non-0 values.

What Now?

As you’ve probably already noticed, several details were left aside. Questions like What is the width of a floated element? or Why doesn’t the padding of an inline element influence the size of the parent block? or What is a run-in box and why would I need one? will all be subject to future articles. Soon, we’ll be discussing the inline formatting context, so if you have questions on inline elements and their misunderstood behavior, they will be answered.

Google I/O 2013 (Or Better Yet 1983)

According to biographers, in the eighties, Steve Jobs was kind of obsessed about IBM. This is one of the reasons for which he approved the famous commercial below, one that was hardly liked by the rest of the directors. It was a bold move, mostly because Steve believed that stopping IBM was his messianic mission.

YouTube Preview Image

The truth is that, right now, the world is hundreds of miles closer to 1984 than it ever was in the eighties. Read more

Infrastructure Clouders Needed

The Infrastructure Team handles the cloud back-end, i.e. the physical and software infrastructure that runs the SaaS platform. Technically, it handles everything from networking to databases. It may not seem very complicated, but it actually takes a broad range of knowledge to understand, operate, and maintain an infrastructure that deals with networking equipment, physical servers, virtualization, storage, databases, communication layers, load balancers etc.

For simplification purposes, we try to use IaaS services without exception. However, this is not always the case on account of costs, availability or performance. This team has both hardware and software capabilities, because the two functions are highly related.

DSC_8639_2

Why We Need Your Talent

The Infrastructure Team is a new entity inside our company. Similarly to a newborn, we have a lot of work on our hands :) so we do need the talent of a good cloud infrastructure engineer.

Infrastructure translates into provisioning and managing every hardware and software on top of which the back-end platform works. Indirectly, this infrastructure is also used by Apps that run on the customer’s device of choice.

We like automation, but not everything can be automated. In the same time, someone needs to create and maintain automation tools. Furthermore, in infrastructure, we must take precise steps and document everything, that’s why you are expected to do this as well.

We like to think big. This means that provisioning one computing node or 1000 must be done in the same way. We’re lazy by nature, :D meaning that writing automation tools is an important part of the job. Monitoring and intervention is also semi-automated. Still, there are things that only humans can excel at. In many cases, it’s also required to research on the best tools, potential problems or things that can be optimized. Bottom line, it’s a never-ending process.

What You Should Know

If you really want to learn new things, then you’re the right candidate. We need that kind of a person that loses sleep trying to understand why a machine randomly kernel panics. Our teammate must think virtualized (we prefer OpenVZ and VMware) and be able to see the bigger picture and design distributed stuff that is not directly bound to a single physical computer.

You need a good understanding of the cloud and excellent Linux OS, tools, and popular services knowledge. Also worth knowing is that previous system administration experience will help you dramatically.

Let’s not forget that the general understanding of the TCP/IP stack, including application layer protocols such as HTTP, is equally important. The cloud is very sensitive to input/output, therefore we expect you to have an overall good IT security knowledge.

Last, but not least, you must be proactive in the way you think, the way you anticipate problems, everything. We like to use the monitoring information to avoid problems. Waiting for them to occur first is not our style.

We know that there is no such thing as an ideal candidate, but if you can significantly match the conditions above, if you’re willing to learn new things, and like playing with new technologies, then we’ll be glad to work side by side with you.

What We Offer

Prove us that you love Linux and the cloud philosophy and that you have broad experience from scripting to the Linux kernel. :)

You’ll get the chance to work with cutting-edge technology on next generation solutions. You will experiment a lot with hardware and software. We’ll teach you what we know about clouds, i.e. storage, databases, networking, virtualization, automation, provisioning etc., their strong points, their weaknesses as well as the way to overcome them. And most important, you will get to learn a lot while helping us build a global IT infrastructure that will power the next 4PSA projects.

If you are interested in this position, drop us an email at jobs AT 4psa.com or simply apply online.

Dynamic Methods in Static-Typed Languages

One of the great benefits of dynamic-typed languages is that they are able to add functionality to an object on run-time. For example, you can create an object and then add functions to it, giving it the desired behavior, without a complex inheritance structure. Moreover, when calling the object’s methods, the client can determine whether the object supports a certain operation or not.

Static-typed languages do not come with this advantage. Creating objects that share some behavior can be done by inheritance, yet this restricts the combinations of behaviors an object can have (unless it relies on multiple-inheritance, which has some tricky effects). Read more

Browsers. The Final Threshold

Have you ever wondered about the purpose of browsers? And why are there so many of them, when they all seem to do the same thing?

Browsers are actually an essential part of the Internet. Without them, the whole world wide web would be meaningless. They are the entities that interface the work of web developers with the user experience. This is why browsers are so important. Read more

App Testing Is Fun

The Apps Team is growing! We are on the look-out for talented software developers with a passion for research and automation testing to join our team in Bucharest.

Many people associate the software testing process with the image of a robot clicking on different links in an attempt to spot issues. Can’t really blame them, as in some cases this is quite necessary. Still, generally speaking, software testing is anything but trivial. As a matter of fact, software testing is software development, with the difference that the output is a software product that tests another software product. On many occasions, developing such a product turns out to be more creative than developing the software that has to be tested.

In the Apps Team, we play with HTML5 Apps that are capable of running on any device. The framework at their core relies on the continuous development of testing tools that allow to check the App behavior without actually experiencing it in the browser or on a mobile device.

What You Should Know

Programming skills are required, particularly JavaScript, Java, PHP, Ruby, or Python. Since the Apps Team’s main goal is to develop cross browser and cross device Apps, it goes without saying that we must test them everywhere, in any context. We take pride in building stable and portable applications that provide a great user experience. That’s why programming skills are not enough – analytic, detail-oriented criticism and excellent problem solving/troubleshooting skills will come in handy. In short, we are asking for an “artistic” eye and good UX understanding. Also, previous experience with applications using HTML5 and CSS3 is much appreciated.

Building performance and secure software has always been an imperative for us. If you do not know much about performance and security testing, we will teach you, but keep in mind that you still need Statistical Mathematics knowledge. Otherwise, you will not be able to render consistent results.

We are an Agile environment and this enables us to meet tight deadlines without cutting down on quality. We expect that everybody gives realistic estimates on the effort required to complete a task and meet deadlines.

If you had no trouble in understanding our requirements so far, then you’re on the right track. ;) Your English must be good. It’s important because you’ll need it.

What You’ll Be Doing

In software development, it all starts with the technical specifications, or requirements if you wish. First of all, you should understand these specifications and imagine as many usage scenarios as you can. Then, you’re expected to analyze and decompose a complicated software system and design strategies to test this system. Daily responsibilities include test case design, manual and automated integration and regression testing, bug reporting and verification of fixed issues.

In many situations, a lot of research is required. Some things simply do not work as expected, but the behavior is not consistent, therefore the only solution is to find the root of the problem or, at least, the root of the inconsistent behavior.

What We Offer

We welcome both young and experienced engineers. Also keep in mind that we value and appreciate experience based on things you can prove, rather than on “working years”.

YouTube Preview Image
 
Some people say that SQA jobs are boring, but at 4PSA, you will have a lot of fun doing this. ;) So, go ahead, contact us at jobs AT 4psa.com or apply directly online for any of our current openings.

We Welcome App Software Engineers

People want and need more and more Apps, and we have to keep up with them. VoipNow users request numerous Apps from us and, as our products are constantly evolving, this trend will certainly go on for a long time. Our Apps Team needs to deal with all these demands at a fast pace. Furthermore, the JavaScript framework at the core of all Apps must be continuously improved and extended with new mechanisms and features. Read more

Older Posts →

© Copyrights 2013 Rack-Soft. 4PSA is a registered trademark of Rack-Soft, Inc.