MHNetwork icon indicating copy to clipboard operation
MHNetwork copied to clipboard

Feature request - optional params

Open Gargo opened this issue 5 years ago • 2 comments

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

Gargo avatar Jun 02 '19 10:06 Gargo

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

emadhegab avatar Jun 02 '19 10:06 emadhegab

@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.

Gargo avatar Jun 02 '19 17:06 Gargo