Open shreyas1599 opened 3 years ago
refactor this into a single fetchBb method
OK. BTW, the http
lib seems a bit verbose when using the HTTP method other than 'GET'.
Currently it is:
http.get()
http.post()
But for the common request utility function, what we want is more like:
http.request(method: MethodEnum.GET)
http.request(method: MethodEnum.POST)
So we could pass the HTTP method enum directly
Oh do you mean using this function:
http.Request(method: String, URL: Uri)
and then Something like this?
enum Methods {
GET, POST,...
}
extension parsdUri on Methods {
Uri getParsedUri(params) {
}
}
http.Request(method: methodName, Methods.GET.getParsedUri(params))
But the above seems will not make the existing code simpler. Are you talking more along these lines: https://github.com/dart-lang/language/issues/158 ? Seems like we can't create methods in enums. Only using extensions we can call methods
Yeah, I mean if the http
lib does already support this, the code would be simpler. For example, we could get rid of the switch case
as follows:
We could just pass the method
instead, no matter if it is a string
or enum
I think your proposal is fine. Let's just do the refactor as you supposed.
Hi, @pd4d10
fetchBb
andfetchBbJson
are two different methods. I need to add other HTTP methods(PUT, DELETE, PATCH) like I did for Gitee. Is it alright if I refactor this into a singlefetchBb
method and update the references across all files? Also was there any specific reason you used two methods(fetchBb and fetchBbJson) for bitbucket unlike the others?