 }
 
 public extension URLRequest {
+    
+    /// Adds or replaces all header fields with the given values.
+    ///
+    /// - note: If a value was previously set for the given header
+    /// field, that value is replaced.
     mutating func apply(header: Parameters?) {
         header?.forEach { setValue($1, forHTTPHeaderField: $0) }
     }
 }
 
 public extension URL {
+    
+    /// `true` if `self` has no scheme.
+    ///
+    /// - note: Used by `BaseClient.encode` to determine if a `URLRequest` should be
+    /// encoded using `self` alone (when `false`) or in combination with
+    /// its `baseURL` (when `true`).
     var isRelative: Bool {
         return scheme == nil
     }
     
-    //creates a relative url
+    /// Creates a relative URL with a given `path` and `query` Dictionary.
     init(path: String?, query: Parameters?) {
         var components = URLComponents()
         components.path = path ?? ""

    }
}

public struct FormEncodedBody: Body {
    public var parameters: Parameters
    
    public init(parameters: Parameters) {
        self.parameters = parameters
    }
    
    public var header: Parameters? {
        return [ "Content-Type" : "application/x-www-form-urlencoded" ]
    }
    
    public var requestData: Data {
        return parameters.map { key, value in
            return "\(encode(key))=\(encode(value))"
        }.joined(separator: "&").data(using: .utf8)!
    }
    
    func encode(_ string: String) -> String {
        guard let encoded = string.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
            fatalError("failed to encode param string: \(string)")

    }
}

/// A `Body` that represents a JSON encoded HTTP request body.
public struct JSONEncodedBody: Body {
    public let requestData: Data
    
    /// Initialize with a JSON object, an `Array` or a `Dictionary`.
    ///
    /// - throws: The error thrown by `JSONSerialization.data(withJSONObject:options:)`, if `jsonObject`
    /// cannot be encoded.
    public init(jsonObject: Any) throws {
        requestData = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
    }
    
    /// Returns "Content-Type": "application/json".
    public var header: Parameters? {
        return [ "Content-Type" : "application/json" ]
    }
}

/// A type that can transform itself into an `URLRequest`.
///
/// This protocol is adopted by `Request`, `URLRequest`, `URL` and `Call`.
public protocol URLRequestEncodable: CustomDebugStringConvertible {
    
    /// Returns an `URLRequest` configured with the data encapsulated by `self`.
    var urlRequest: URLRequest { get }
}

extension URLRequestEncodable {
    
    /// Returns the value returned by `cURLRepresentation`.
    public var debugDescription: String {
        return cURLRepresentation
    }
}

/// A type that encapsulates all data necessary to construct an `URLRequest`
/// suitable for a typical REST-API call.
/// 
/// You can (and should) use this instead of a plain `URLRequest`, because it's
/// usually much more convenient and easier to read.
public struct Request: URLRequestEncodable {
    public var method: HTTPMethod
    public var url: URL
    public var header: Parameters?
    public var body: Body?
    
    /// Creates a relative Request
    public init(_ method: HTTPMethod, _ path: String?=nil, query: Parameters?=nil, header: Parameters?=nil, body: Body?=nil) {
        self.init(method, url: URL(path: path, query: query), header: header, body: body)
    }
    
    /// Creates an absolute Request
    public init(_ method: HTTPMethod, url: URL, header: Parameters?=nil, body: Body?=nil) {
        self.method = method
        self.header = header
