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

Add allowing generic HTTP POST body #94

Open
Slord6 opened this issue Dec 23, 2020 · 8 comments
Open

Add allowing generic HTTP POST body #94

Slord6 opened this issue Dec 23, 2020 · 8 comments

Comments

@Slord6
Copy link

Slord6 commented Dec 23, 2020

As per discussion #92 , it would be useful to be able to have control over the full body of HTTP POST requests.

For example, I have a simple HTTP wrapper around a JSON-backed database, which expects POST requests to contain only the data to be added to the database. At the moment it is therefore not possible to POST data with Phonk to that end-point.

Example code + expected data at discussion #92

@victordiaz
Copy link
Owner

@Slord6 I uploaded a new version here for you to test https://github.com/victordiaz/PHONK/releases/tag/1.3.3pre
Let me know how it goes :)

@Slord6
Copy link
Author

Slord6 commented Dec 24, 2020

That's working great. Thanks!

@Slord6 Slord6 closed this as completed Dec 28, 2020
@SeriousM
Copy link

Is there any chance to get a new release with this enhancements included?

@Slord6
Copy link
Author

Slord6 commented Jan 29, 2021

I think it was already released. In 1.3.1 looking at the release notes. My last use of it looks like:

const sendData = (data) => {
  data.client = "Phone";
  data.satCount = satCount;
  console.log("Sending: " + JSON.stringify(data));
  network.httpRequest({
   method: 'POST',
  url: url,
  body: {
    type: 'application/json',
    data: JSON.stringify(data)
  }}).onResponse(function (e) {
    console.log(e.status, e.response);
  })
}

@victordiaz
Copy link
Owner

it should work on 1.40 too unless I screwed up at some point upgrading stuff :)

@Slord6 btw thx! you just made me realize with your code that at some point Mozilla Rhino interpreter got fat arrows and const!!!!
I didnt know at all!.
On top of that I just realized that toggling a flag we can finally have let and destructuring support :)

I'll release a new version during the weekend, thx for sharing that code!

@Slord6
Copy link
Author

Slord6 commented Jan 29, 2021

Oh nice, it hadn't even occurred to me they weren't supported so glad it's helpful!

@SeriousM
Copy link

@victordiaz thanks for looking into it.

In v1.3.3pre I had the option to use

  network.httpRequest({
    method: 'POST',
    url: 'https://bzzzzzzz.com/bzzzzz',
    body: {
      type: 'application/json',
      data: JSON.stringify([input.text()])
    }
  }).onResponse(function (e) {

but with v1.4.0 I get the error java.lang.IllegalArgumentException: method POST must have a request body. as with previous versions.

I hope you can include the specific code in the upcoming version!
Thank you very much for this wonderful framework :)

@victordiaz
Copy link
Owner

@SeriousM you are right, it does not work currently. It seems I didnt merge properly 😅
I'll try to upload a new version today or tomorrow fixing the issue.

@victordiaz victordiaz reopened this Jan 30, 2021
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

3 participants