Skip to content

Give the possibility to provide custom headers #290

@bidoubiwa

Description

@bidoubiwa

As for #283 the different requests method provide headers as an optionnal parameter.
Nonetheless, if we go up in the stack of calls, no headers are passed to these methods. We should be able to pass them.

For example here:

func get<T>(
_ uid: String,
_ identifier: String,
_ completion: @escaping (Result<T, Swift.Error>) -> Void)
where T: Codable, T: Equatable {
let query: String = "/indexes/\(uid)/documents/\(identifier)"
self.request.get(api: query) { result in
switch result {

the request.get does not provide the headers that can be passed as an argument here

func get(
api: String,
param: String? = nil,
headers: [String: String] = [:],
_ completion: @escaping (Result<Data?, Swift.Error>) -> Void) {

We should be able to provide the information.

Two possible solutions this.config can contain the specific headers. In which case we can remove the headers params from the request methods.

Or we provide them as an optional parameter for each method:

 public func createIndex(
    uid: String,
    primaryKey: String? = nil,
    headers: [String: String] = [:],
    _ completion: @escaping (Result<Task, Swift.Error>) -> Void) {
    Indexes.create(uid: uid, primaryKey: primaryKey, config: self.config, completion)
  }

I prefer the first option but this also means an additional parameter during the initialisation of a Meilisearch client.

  public init(
     host: String,
     apiKey: String? = nil,
     session: URLSessionProtocol? = nil,
     request: Request? = nil,
     headers: [String: String] = [:]) throws {

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions