Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sample request model that can be converted to a MutableURLRequest
class Request {
var url: String
var requestType: RequestType
var body: NSData?
var headers: Dictionary<String, String>?
init(url: String, requestType: RequestType, body: NSData?, headers: Dictionary<String, String>?) {
self.url = url
self.requestType = requestType
if body != nil {
self.body = body!
if headers != nil {
self.headers = headers!
func toMutableURLRequest() -> NSMutableURLRequest {
println("Setting up URL: \(url)")
var request = NSMutableURLRequest(URL: NSURL(string: url)!)
println("Setting up request type: \(requestType.rawValue)")
request.HTTPMethod = requestType.rawValue
request.HTTPBody = body
if let newHeaders = headers {
for (key, value) in newHeaders {
request.addValue(value, forHTTPHeaderField: key)
return request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.