Pular para o conteúdo principal

Postagens

Mostrando postagens de Março, 2013

Very short REST client in Ruby

I've studied Ruby for 2 years. I feel Ruby like Lego blocks: it is cool, funny, and you could even build a wall with this easily but it could be expensive to make a very solid wall.

Anyway, here is a funny to.  Look how simple is to do a Getter REST client in ruby (you could try RESTfolia, restfulie, etc). I call Getter REST client because, it just for GET requests.

require "net/http" require "uri" require 'json' require 'methodize' uri = URI.parse("http://localhost:8080/jdb/list") response = Net::HTTP.get_response(uri) json = JSON.parse(response.body) json.extend(Methodize)

With authentication, we get:
req = Net::HTTP::Get.new(uri.request_uri) req.basic_auth 'user', 'password' res = Net::HTTP.start(uri.hostname, uri.port) {|http| http.request(req) } json = JSON.parse(res.body) json.extend(Methodize)
That is it!

What happens when you click on submit button

HTTP over TCP/IP Suite


Maybe someone asks you about what happens when you click on submit button in a web browser. That question is in fact a very recurrent question in interviews for Software Engineers, Web Developers and so on. I  really suggest you take a look at RFC specifications.

Before you deep dive into RFCs (Internet Protocol, IP (1981)  - RFC 791; Transfer Control Protocol, TCP - RFC 793; and Hyper Text Transfer Protocol 1.1, HTTP/1.1 - Roy Fielding et al, RFC 2616) I advise you to look at some links before (yeah, it is a hard way to the top if you wanna rock'n'roll):

Eventhelix.com has created a very insightful tool to understand network interactions.  Take a look here (you need to have some previous knowledge about network vocabulary): http sequence diagram in pdfAre you very green at HTTP? Ok... here is a good introduction: http_basics (ntu.edu.sg)Always useful to know how to use curl and what the heck is x-www-form-urlencoded... take a look at superuser.com (from …