def execute
      # Here is the order of operations:
      # -> setting @data_sent
      # -> executing before_request_execution callback
      # -> executing the HTTP request
      # -> setting @response
      # -> setting @data_received
      # -> executing after_request_execution callback

      # Setting @data_sent
      params = Rack::Utils.parse_nested_query(URI.parse(@http_request.path).query)
      # Since that's how it will be interpreted anyway on the server, we merge the POST params to the GET params,
      # but it's not supposed to happen: either every params is prepared for GET/query params, or as POST body
      params.merge!(Rack::Utils.parse_nested_query(@http_request.body.to_s))

      # About: Hash[{}.map{|k,v| [k, v.join] }]
      # it transforms the following hash:
      # {"accept"=>["*/*"], "user-agent"=>["TheBigDB RubyWrapper/X.Y.Z"], "host"=>["computer.host"]}
      # into the following hash:
      # {"accept"=>"*/*", "user-agent"=>"TheBigDB RubyWrapper/X.Y.Z", "host"=>"computer.host"}
      # which is way more useful and cleaner.
      @data_sent = {
        "headers" => Hash[@http_request.to_hash.map{|k,v| [k, v.join] }],
        "host" => @http.address,
        "port" => @http.port,
        "path" => URI.parse(@http_request.path).path,
        "method" => @http_request.method,
        "params" => params
      }

      # Executing callback
      TheBigDB.before_request_execution.call(self)

      # Here is where the request is actually executed
      @http_response = TheBigDB.http_request_executor.call(@http, @http_request)

      # Setting @response
      begin
        # We parse the JSON answer and return it.
        @response = JSON(@http_response.body)
      rescue JSON::ParserError => e
        @response = {"status" => "error", "error" => {"code" => "0000", "description" => "The server gave an invalid JSON body:\n#{@http_response.body}"}}
      end

      # Setting @data_received
      @data_received = {
        "headers" => Hash[@http_response.to_hash.map{|k,v| [k, v.join] }],
        "content" => @response
      }

      # Executing callback
      TheBigDB.after_request_execution.call(self)

      # Raising exception if asked
      if TheBigDB.raise_on_api_status_error and @response["status"] == "error"
        raise ApiStatusError.new(@response["error"]["code"])
      end

      self
    end
def execute
      # Here is the order of operations:
      # -> setting @data_sent
      # -> executing before_request_execution callback
      # -> executing the HTTP request
      # -> setting @response
      # -> setting @data_received
      # -> executing after_request_execution callback

      # Setting @data_sent
      params = Rack::Utils.parse_nested_query(URI.parse(@http_request.path).query)
      # Since that's how it will be interpreted anyway on the server, we merge the POST params to the GET params,
      # but it's not supposed to happen: either every params is prepared for GET/query params, or as POST body
      params.merge!(Rack::Utils.parse_nested_query(@http_request.body.to_s))

      # About: Hash[{}.map{|k,v| [k, v.join] }]
      # it transforms the following hash:
      # {"accept"=>["*/*"], "user-agent"=>["TheBigDB RubyWrapper/X.Y.Z"], "host"=>["computer.host"]}
      # into the following hash:
      # {"accept"=>"*/*", "user-agent"=>"TheBigDB RubyWrapper/X.Y.Z", "host"=>"computer.host"}
      # which is way more useful and cleaner.
      @data_sent = {
        "headers" => Hash[@http_request.to_hash.map{|k,v| [k, v.join] }],
        "host" => @http.address,
        "port" => @http.port,
        "path" => URI.parse(@http_request.path).path,
        "method" => @http_request.method,
        "params" => params
      }

      # Executing callback
      TheBigDB.before_request_execution.call(self)

      # Here is where the request is actually executed
      @http_response = TheBigDB.http_request_executor.call(@http, @http_request)

      # Setting @response
      begin
        # We parse the JSON answer and return it.
        @response = JSON(@http_response.body)
      rescue JSON::ParserError => e
        @response = {"status" => "error", "error" => {"code" => "0000", "description" => "The server gave an invalid JSON body:\n#{@http_response.body}"}}
      end

      # Setting @data_received
      @data_received = {
        "headers" => Hash[@http_response.to_hash.map{|k,v| [k, v.join] }],
        "content" => @response
      }

      # Executing callback
      TheBigDB.after_request_execution.call(self)

      # Raising exception if asked
      if TheBigDB.raise_on_api_status_error and @response["status"] == "error"
        raise ApiStatusError.new(@response["error"]["code"])
      end

      self
    end
Actually makes the request prepared in @http_request, and sets @http_response