enonic / lib-http-client

Http Client Library for Enonic XP.
Apache License 2.0
0 stars 4 forks source link

Support PATCH HTTP method #54

Closed jonaslepsoy closed 3 years ago

jonaslepsoy commented 3 years ago

The lib only supports "POST", "GET", "HEAD", "PUT", "DELETE". It should also support "PATCH".

This would be useful if some service modifies only some data fields and not all (where a PUT would be proper).

ComLock commented 3 years ago

I need this for our FotoWare integration app.

rymsha commented 3 years ago

Do you have a test example that demonstrates "PATCH" not working?

ComLock commented 3 years ago

Well it requires an auth token, so it's a bit of work to setup...

rymsha commented 3 years ago

Doc says

method (string) The HTTP method to use for the request (e.g. "POST", "GET", "HEAD", "PUT", "DELETE"). The default value is "GET".

But it does not mean that "PATCH" is not supported. e.g. here translates to "for example".

ComLock commented 3 years ago

You can't trust the docs...

This doesn't work: https://github.com/enonic/app-fotoware/blob/master/src/main/resources/lib/fotoware/api/asset/update.es#L40

However sending the exact same parameters through Postman works fine.

rymsha commented 3 years ago

simple server: nc -l localhost 8000

how to send patch

var http = require('/lib/http-client');

var result = http.request({
      url: 'http://localhost:8000/my/url',
      method: 'patch',
      body: 'PATCH body'
});

nc Output

PATCH /my/url HTTP/1.1
Content-Length: 10
Host: localhost:8000
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/4.9.1

PATCH body

Library supports PATCH

ComLock commented 3 years ago

Sooo method: 'patch' works, but method: 'PATCH' fails?

ComLock commented 3 years ago

Notice the doc uses UPPERCASE letters in the example https://developer.enonic.com/docs/http-client-library/master#usage

ComLock commented 3 years ago

Even the API doc https://developer.enonic.com/docs/http-client-library/master#api

rymsha commented 3 years ago

PATCH or patch doesn't matter. value gets uppercased.

ComLock commented 3 years ago

Could you try the same request you did above with Postman, just to see if there are any other differences than User-Agent?