-
Notifications
You must be signed in to change notification settings - Fork 26
Refactor the request function to use a simple request builder #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
4168c64
to
066deb1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that only the get
method takes the headers
as argument.
@ppamorim I saw that you were the one that added the header as argument in the get method. Is this something on purpose or should it be added in the other methods as well?
DOn't worry I can do the PR, I was just wondering if there is a reason for this
func get(
api: String,
param: String? = nil,
headers: [String: String] = [:],
@bidoubiwa I can't approve your suggestions because Github is not accepting my request. |
Hey @ppamorim tell me if it fixed, if it isn't I can commit for you if you'd like to! |
@bidoubiwa It's not. I could not hear from Github. |
Okey I will make the changes asap! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot 🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR @ppamorim 💪
Feel free to apply or not the suggestions I made :)
_ headers: [String: String] = [:], | ||
data: Data? = nil | ||
) -> URLRequest { | ||
var request = URLRequest(url: url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var request = URLRequest(url: url)
request.httpMethod = httpMethod.rawValue
request.setValue(PackageVersion.qualifiedVersion(), forHTTPHeaderField: "User-Agent")
if httpMethod != .get {
request.httpBody = data
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
}
if let apiKey: String = config.apiKey {
let bearer = "Bearer \(apiKey)"
request.setValue(bearer, forHTTPHeaderField: "Authorization")
}
headers.forEach { key, value in
request.addValue(value, forHTTPHeaderField: key)
}
return request
I added some spaces between functions, I think they were important (it is easier to read :D).
But I changed some function execution orders as well, this will help anyone to apply custom data from the headers
param when needed (idk, if to fully apply this concept we need to switch over setValue
instead of addValue
).
bors try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks for the contribution! ❤️
bors merge |
Build succeeded: |
Pull Request
What does this PR do?
Fixes issue pointed on #272
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!