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

adding request method into request method params #52

Closed
bekbergenb opened this issue Jan 31, 2020 · 1 comment · Fixed by #94
Closed

adding request method into request method params #52

bekbergenb opened this issue Jan 31, 2020 · 1 comment · Fixed by #94

Comments

@bekbergenb
Copy link

bekbergenb commented Jan 31, 2020

Is there any way to put request method into request method parameters like in python?
currently we make request like this in scala

method match {
        case "post" =>
          val res = requests.post(url, data = Map("key" -> "Value"))
          println(s"status: ${res.statusCode} message: ${res.statusMessage} method ${res.headers}")
        case "get" =>
          val res = requests.get(url=url)
          println(s"status: ${res.statusCode} message: ${res.statusMessage} method ${res.headers}")
      }

but in python we can do

requests.request(method=method, url=url, data=data)
@bekbergenb bekbergenb changed the title adding request method into params adding request method into request method params Jan 31, 2020
@lihaoyi
Copy link
Member

lihaoyi commented Dec 10, 2021

You should be able to do:

@ requests.Requester("GET", requests.`package`).apply("https://www.google.com")
res0: requests.Response = Response(
  url = "https://www.google.com",
  statusCode = 200,
  statusMessage = "OK",
  data = <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-SG"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/logos/doodles/2021/seasonal-holidays-2021-6753651837109324-6752733080595605-cst.gif" itemprop="image"><meta content="Seasonal Holidays 2021" property="twitter:title"><meta content="Seasonal Holidays 2021 #GoogleDoodle" property="twitter:description"><meta content="Seasonal Holidays 2021 #GoogleDoodle" property="og:description"><meta content="summary_large_image" property="twitter:card"><meta content="@GoogleDoodles" property="twitter:site"><meta content="htt

@lihaoyi lihaoyi closed this as completed Dec 10, 2021
lihaoyi added a commit that referenced this issue Dec 10, 2021
Fixes #67
Fixes #52

This was always possible in a roundabout way via


```scala
requests.Requester("get", requests.Session()).apply("https://www.google.com")
```

But this PR adds a convenient alias and documents it for discoverability

```scala
requests.send("get")("https://www.google.com")
```
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

Successfully merging a pull request may close this issue.

2 participants