# Just learn Rails (Part 3) HTTP status codes

DevFeed: [Just learn Rails (Part 3) HTTP status codes](<https://devfeed.tech/articles/just-learn-rails-part-3-http-status-codes-21042.md>)

Original publisher: [Read original article](<https://jakeyesbeck.com/2015/09/20/rails-http-status-codes/>)

Published: 2015-09-20T12:00:00Z

Content type: article

Language: en

Sources: [Jake Yesbeck](<https://devfeed.tech/sources/jake-yesbeck.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [HTTP](<https://devfeed.tech/topics/http.md>), [API](<https://devfeed.tech/topics/api.md>), [Authorization](<https://devfeed.tech/topics/authorization.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [authorization](<https://devfeed.tech/tags/authorization.md>), [code](<https://devfeed.tech/tags/code.md>), [http](<https://devfeed.tech/tags/http.md>), [rails](<https://devfeed.tech/tags/rails.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [stateless](<https://devfeed.tech/tags/stateless.md>)

## AI overview

This article explains why HTTP status codes matter when building APIs with Ruby on Rails. It describes how status codes communicate the result of requests, including successful lookups, missing resources, server errors, and authorization failures.

## Source excerpt

So you want to be a Rails superstar? To live large, big servers, requesting tars. Writing code all over the world, gotta make commits constantly. Great, I feel the same way. Assuming you have already had that "I should just learn Rails" moment, the idea of writing an API for a super awesome application might be on the horizon. And, of course, the framework that makes the most sense is Ruby on Rails. Given that is the direction things might naturally evolve, creating an API with Rails can gloss over a few crucial design concepts and considerations. HTTP status codes are important When the Hypertext Transfer Protocol (or HTTP) was conceived, the idea of a server responding with multiple distinct pieces of data came into existence. Officially, HTTP is a stateless application-level protocol for distributed, collaborative, hypertext information system. In other words, it is a standard way that one server can talk to another in a predefined fashion. This is especially useful when writing a system that will facilitate requests from someone other than the person which built it; e.g. an HTTP API. The aspect of HTTP that is most relevant in this post are status codes. These codes explicitly tell consumers of an application how they should react to a request. From authorization issues to an incorrect arity of parameters, a large amount of information is exposed via HTTP status codes. Rails status code support Let us assume that an application exists to look up information about books. To get a specific book, a RESTful route is provided by the application at https://mycoolbookapp.com/books/12. This route might execute the following controller action: class BooksController < ApplicationController def show render json: Book.find(params[:id]) end end This simple controller action can respond with three HTTP status codes. A 200 will be in the response of any Book which matches the :id supplied. Likewise, a 404 will automatically be returned if the Book requested does not exist. Fin