1

I'm trying to write a http rest client for my webservice and i need to send some PATCH requestes with data in the body.

I'm using the JUST library for sending requests ( https://github.com/JustHTTP/Just )

My express application just doesn't see the request. Here's some code (i'm testing in playground, and everything went fine with other kind of requests like put, post...)

headers = ["accept":"application/json","content-type":"application/json","authorization":"key"] //key is ok

var data = ["id":3, "quantity":6] 

var r =   Just.patch("http://api.marketcloud.it/v0/carts/1233", headers:headers, data:data) //1233 is a cart Id

print(r)
print(r.json)

The method Just.patch returns an HTTPResult Object. this says 'OPTIONS http://api.marketcloud.it/v0/carts/13234 200'

Also this object should contain a json, but it's 'nil'.

On the server-side, my express applications doesn't receive the request (it just logs an 'OPTION', but nothing else).

Could this be a playground-related problem? Or a just-related one?

Thanks for any suggestion

Mirco Lcl
  • 373
  • 7
  • 19
  • 1
    Your request's status code is 200 (`print(r.statusCode)`), so I guess the problem is on the server side if you still don't see your data. – Eric Aya Feb 02 '16 at 14:12
  • Thanks @Eric D. , unfortunately I'm pretty sure the problem is not server-side because I have a javascript client that does the same kind of requests and there are no problems related to 'patch' ones.. – Mirco Lcl Feb 02 '16 at 14:35
  • 1
    You may be right indeed. By curiosity I replaced `patch` by `put` for your request and suddenly we do get back some JSON - I believe it should happen for patch also. – Eric Aya Feb 02 '16 at 14:39
  • You're right, in the documentation there are some calls with the PUT method. Even in case there's an error, a JSON should return, and it returns. I suppose the problems is strictly related to the Patch call from Swift. I'm not sure if it's 'Just' fault or not, I think i'm going to try another way to do the Patch request in order to understand better... – Mirco Lcl Feb 02 '16 at 14:49

1 Answers1

0

I managed to contact the library's author via twitter and he fixed the bug and answered me in less than 24h!

Here's the new release of the library.

https://github.com/JustHTTP/Just/releases

Mirco Lcl
  • 373
  • 7
  • 19