nealrichardson / httptest

A Test Environment for HTTP Requests in R
https://enpiar.com/r/httptest/
Other
79 stars 10 forks source link

Support of POST requests #3

Closed byapparov closed 7 years ago

byapparov commented 7 years ago

Hi,

I am looking to add support of POST requests to your package and at this point not sure why did you restrict it to GET in the first place.

How do you think the path to a fake file will be different?

Thanks Bulat

nealrichardson commented 7 years ago

I didn't implement it initially because I didn't need it; the APIs I was working with were mostly CRUD, so POST was a write, not a read.

I left a comment for where I'd handle it: https://github.com/nealrichardson/httptest/blob/master/R/mock-api.R#L83

Probably like:

if (method != "GET") {
    f <- paste0(f, "-", method)
}

Also would need to remove the "GET" method checks in https://github.com/nealrichardson/httptest/blob/master/R/mock-api.R#L34.

That'll work if you're looking to mock a POST (or any other verb) that returns 200 status with content. Anything else (other statuses, headers, etc.) will be more involved to implement.

byapparov commented 7 years ago

Hi Neal,

Thank you for details, I think this should get me going.

Some data related APIs have two step execution, where the first call is POST with request details (e.g. query) and second call is a GET to URI from the initial POST.

I want to make tests on the original post to see that URI can be extracted.

byapparov commented 7 years ago

Now is addressed here: https://github.com/nealrichardson/httptest/pull/4