Skip to content
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

formParameters doesn't work #13

Open
samthebest opened this issue Aug 11, 2023 · 1 comment
Open

formParameters doesn't work #13

samthebest opened this issue Aug 11, 2023 · 1 comment

Comments

@samthebest
Copy link

cc @stacycurl

I have to construct the query params my self, if I use formParameters on a request it doesn't seem to work (I get 404).

  def get(uri: String, params: Map[String, String]): Future[Response] = {
    val formParams: List[FormParameter] = params.map(kv => FormParameter(kv._1, kv._2)).toList

    val paramSuffix: String = if (params.isEmpty) "" else s"?${params.map(kv => kv._1 + "=" + kv._2).mkString("&")}"

    Future {

      // Works
      http(
        GET(uri + paramSuffix)
      )

      // Not work
      http(
        GET(uri)
          .formParameters(formParams: _*),
      )
    }
  }

Also FormParameter seems like a fairly redundant type, could just use Map[String, String]

@stacycurl
Copy link
Contributor

@samthebest I'd be happy to pair with you to explore this.

FormParameter is part of naive-http's domain (although not as central as Request, Response, etc), Map[String, String] is not.

Map[String, String] may very well be a fine underlying encoding, it's a terrible representation/api as it has nothing to do with form parameters. The domain of http deserves to be first class (especially in a library about http !), whilst also being careful not to gatekeep / be rigid / drown in NIH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants