emadhegab / MHNetwork

Say goodbye to the Fat ugly singleton Network Manager with this Network Layer
MIT License
19 stars 3 forks source link

Feature request - optional params #2

Open Gargo opened 5 years ago

Gargo commented 5 years ago

For example I need a library to collect rss from different websites. I need to specify single url only and get/post method only for each website. You library requires to setup all params even if they are not necessary

emadhegab commented 5 years ago

You can do that for the other functions

‘’’ var parameters: RequestParams { return .url(nil) }

var headers: [String : Any]? {
    return nil
}

‘’’

See if it works for you

Gargo commented 5 years ago

@emadhegab I solved it by the following code:

extension Request {
    var path: String {
        return ""
    }
    var method: HTTPMethod {
        return .get
    }
    var parameters: RequestParams {
        return .url(nil)
    }
    var headers: [String : Any]? {
        return nil
    }
}
enum RTDefaultRequest: Request {
    case `default`
}
extension Operations {
    var request: Request {
        return RTDefaultRequest.default
    }
}

It adds default implementations for these methods and simplifies the development for some cases.