PHPNews

416 Range Not Satisfiable

It’s possible for a client to request partial responses from a server. For example, a client might only want the first 5 minutes of a video, or the last 100 lines of a log file. HTTP clients and servers can do this with range requests. For example, this request asks for the first 100 bytes: GET /foo.md …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday March 19, 2019


An OAuth2 middleware for fetch()

I was a bit frustrated with the existing offerings for OAuth2 clients in Javascript. I heavily use the Fetch API directly, but Web API’s haven’t really caught up to have deep integration with OAuth2. We were using client-oauth2 , but the minified size of this library was close to 40kb which ended up being a …

Continue reading »

Written by Evert Pot - - Aggregated on Thursday March 14, 2019


415 Unsupported Media Type

When a server receives a request with a body it doesn’t understand, it should return 415 Unsupported Media Type . Most commonly this is a good response for for example a POST or PUT request with an unknown Content-Type header. The specification says that aside from inspecting the Content-Type header, …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday March 12, 2019


414 URI Too Long

The URI or path of a HTTP request doesn’t have any hard limits in terms of how long it’s allowed to be. However, Browsers and search engines have limits , and on the server side it’s a good idea to limit the length of the URI to combat certain denial-of-service attacks or bugs. Based on limits of browsers, it’s …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday March 5, 2019


413 Payload Too Large

The 413 Payload Too Large response is used when the client sent a request with a body that’s too big. Maybe the request was a file upload, and it exceeded the maximum file-size, or maybe it’s an API and it preemptively blocks requests that are unrealisticly large. It’s a good idea to try and think of …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday February 26, 2019


412 Precondition Failed

In HTTP it’s possible to do conditional requests. These are requests that only execute if the right conditions are met. For GET requests, this might be done to only retrieve the resource if it has changed. For those cases 304 Not Modified is returned. For other cases, 412 Precondition Failed is returned. …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday February 19, 2019


411 Length Required

Most HTTP requests that have a request body, will also have a Content-Length header indicating how big the body will be. However, this is optional for some cases, such as when Chunked Transfer Coding is used. It’s useful for a client to not include a Content-Length header for a few different cases. For …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday February 12, 2019


410 Gone

410 Gone is a status code that can be used in cases where a resource is gone and never coming back. It’s a more specific version of 404 Not Found . A good example for using 410 instead of 404 is when a resource was intentionally removed. Using 410 can be helpful, because it signals to other people …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday February 5, 2019


Ketting 2.5 release.

Ketting is an attempt at making a generic Hypermedia API client for javascript. It uses a ‘link’ and following links as the most important primitive. Last week I released version 2.5.0 on NPM so maybe it’s time to list some of the improvements since the last update in order from most to least interesting. …

Continue reading »

Written by Evert Pot - - Aggregated on Wednesday January 30, 2019


409 Conflict

409 Conflict is used in cases where the HTTP request was valid, but the current state of the server prevents it from being executed. This is useful for APIs. A few hypothetical examples: A user wants to add a file to a folder, but the folder doesn’t exist yet. Amazon S3 uses it when you try to delete a …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday January 29, 2019


bigint-money: an NPM package for doing currency math

Not long ago, I was confused about doing math with money and floating point issues. After a bunch of research and help from friends I figured out what many already did before me: Using floating points is indeed bad. You can get rounding issues and really want to use ‘precise math’. After that, I realized I wanted …

Continue reading »

Written by Evert Pot - - Aggregated on Wednesday January 23, 2019


408 Request Timeout

If a client is too slow to send a full HTTP request, a server can send back a 408 Request Timeout error response. A request coming in too slow can happen for a variety of reasons, including slow internet connections, completely lost internet connections or bad actors. When a server sends back the 408 , it …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday January 22, 2019


407 Proxy Authentication Required

407 Proxy Authentication Required is an error a HTTP proxy returns if it requires authentication. It’s really similar to 401 Unauthorized . Example HTTP/1.1 407 Proxy Authentication Required Proxy-Authenticate: Basic; realm="Secured area" As you can see above, the response looks pretty similar to 401 …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday January 15, 2019


MySQL examples in Node.js

If you’re integrating your Node.js service with MySQL, you probably want to execute queries. I’ve seen a fair bit of ugly code to do this, often using callbacks. I thought I would share some of my own patterns here. Maybe this is useful to others to read. I don’t typically use ORM’s. If you’re already happy with …

Continue reading »

Written by Evert Pot - - Aggregated on Wednesday January 9, 2019


406 Not Acceptable

Happy 2019! After a small hiatus we’re back with this captivating series. I hope you’re as excited as I am and I hope you have the best 2019! 406 Not Acceptable is emitted by a server when the client asked for a specific representation of a resource that the server doesn’t support. Accept headers HTTP has …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday January 8, 2019


One year in San Francisco as a Software Engineer

In 2017 the company I worked for in Toronto got acquired by Yelp. The software engineers in my company (including myself) were asked to move to San Francisco. At the end of 2017 we moved, and I spent most of 2018 there. With the year coming to an end, I thought it might be a good time to reflect on my time there. …

Continue reading »

Written by Evert Pot - - Aggregated on Thursday January 3, 2019


405 Method Not Allowed

405 Method Not Allowed should be returned by a server when a certain HTTP method is not supported at a resource. It’s a bit different from 403 Forbidden . 403 suggest that the server might support the HTTP request, but the client doesn’t have the right privileges to do the HTTP request. 405 Method Not …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday December 18, 2018


404 Not Found

404 Not Found hardly needs an introduction. It’s by far the most seen status by developers and non-developers alike. 404 is emitted when a resource doesn’t exist, never existed or if the server doesn’t want a client to know that a resource exist. If the server knows the resource doesn’t and will never exist …

Continue reading »

Written by Evert Pot - - Aggregated on Tuesday December 11, 2018


Floats and money

A very common and oft-repeated programmer’s wisdom is “Don’t use floats for currency”. This always made a lot of sense to me. The idea is that floats are imprecise, due to the way they are stored. Effectively floats are stored not by just their digits, but by a formula . This formula can’t accurately represent …

Continue reading »

Written by Evert Pot - - Aggregated on Thursday December 6, 2018