Sinatra Basics : HTTP verbs


To learn about the HTTP verbs GET, POST, PATCH, PUT, DELETE that is used in a RESTful webservice.


Step 1

Create rest.rb:

require 'sinatra'

get '/articles' do
  'listing of all the articles'  

get '/article/:id' do
  'get the article with the given id'

post '/article' do
  'create a new article'

put '/article/:id' do
  'update an existing article'

patch '/article/:id' do
  'update part of the existing article'

delete '/article/:id' do
  'delete the article'

Step 2

Install Advanced REST client chrome extension.

Step 3

Run the application:

bundle exec shotgun rest.rb

Step 4

Play with REST client using the following URLs in REST client Chrome extension.

GET http://localhost:9393/articles
GET http://localhost:9393/article/1
POST http://localhost:9393/article
PUT http://localhost:9393/article/1
PATCH http://localhost:9393/article/1
DELETE http://localhost:9393/article/1


In this article, you learned about the HTTP verbs and saw the request and response using Advanced REST client Chrome extension.

Related Articles

Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.