zfcampus / zf-apigility-admin

Admin API and UI for Apigility
BSD 3-Clause "New" or "Revised" License
90 stars 64 forks source link

PUT Request clear all fields that is not in content #265

Closed Leen15 closed 9 years ago

Leen15 commented 9 years ago

Hi, I'm new with apigility, and i trying to create some Rest API.

if i've an object with:

and i send a PUT request to the entity (like "objects/1" ) with this content: {"property_1":"test"}

All other fields (id and name in this case) are cleared!

Why? I cannot think that i have to pass ALL fields in every PUT request for update only one field of that.

Is it a bug? should i set something in admin?

This is my composer.json for see what i'm using:

{ "name": "zfcampus/zf-apigility-skeleton", "description": "Skeleton Application for Apigility", "type": "library", "license": "BSD-3-Clause", "keywords": [ "api", "apigility", "framework", "zf2" ], "homepage": "http://apigility.org/", "support": { "email": "apigility-users@zend.com", "irc": "irc://irc.freenode.net/apigility", "source": "https://github.com/zfcampus/zf-apigility-skeleton", "issues": "https://github.com/zfcampus/zf-apigility-skeleton/issues" }, "config": { "process-timeout": 5000 }, "extra": { "branch-alias": { "dev-master": "1.0-dev", "dev-develop": "1.1-dev" } }, "require": { "php": ">=5.3.23", "zendframework/zendframework": ">=2.3.2,<3.0.0", "zfcampus/zf-apigility": "~1.0", "zfcampus/zf-apigility-documentation": "~1.0", "zfcampus/zf-development-mode": "~2.0" }, "require-dev": { "zendframework/zftool": "dev-master", "zendframework/zend-developer-tools": "dev-master", "zfcampus/zf-apigility-admin": "~1.0-dev@dev", "zfcampus/zf-apigility-welcome": "~1.0", "zfcampus/zf-deploy": "~1.0" } }

Thanks

jguittard commented 9 years ago

If you intend to update only one field and only part of your entity properties, you need to use PATCH method instead of PUT. If you choose PUT, you have to define all the existing properties even if they're not modified + the ones you want to update. Furthermore, you should rely on PATCH for updating resources and drop PUT for browser compatibility issues.

Julien.

Le 14 mars 2015 à 11:57, Luca notifications@github.com a écrit :

Hi, I'm new with apigility, and i trying to create some Rest API.

if i've an object with:

id name property_1 and i send a PUT request to the entity (like "objects/1" ) with this content: {"property_1":"test"}

All other fields (id and name in this case) are cleared!

Why? I cannot think that i have to pass ALL fields in every PUT request for update only one field of that.

Is it a bug? should i set something in admin?

This is my composer.json for see what i'm using:

{ "name": "zfcampus/zf-apigility-skeleton", "description": "Skeleton Application for Apigility", "type": "library", "license": "BSD-3-Clause", "keywords": [ "api", "apigility", "framework", "zf2" ], "homepage": "http://apigility.org/", "support": { "email": "apigility-users@zend.com", "irc": "irc://irc.freenode.net/apigility", "source": "https://github.com/zfcampus/zf-apigility-skeleton", "issues": "https://github.com/zfcampus/zf-apigility-skeleton/issues" }, "config": { "process-timeout": 5000 }, "extra": { "branch-alias": { "dev-master": "1.0-dev", "dev-develop": "1.1-dev" } }, "require": { "php": ">=5.3.23", "zendframework/zendframework": ">=2.3.2,<3.0.0", "zfcampus/zf-apigility": "~1.0", "zfcampus/zf-apigility-documentation": "~1.0", "zfcampus/zf-development-mode": "~2.0" }, "require-dev": { "zendframework/zftool": "dev-master", "zendframework/zend-developer-tools": "dev-master", "zfcampus/zf-apigility-admin": "~1.0-dev@dev", "zfcampus/zf-apigility-welcome": "~1.0", "zfcampus/zf-deploy": "~1.0" } }

Thanks

— Reply to this email directly or view it on GitHub.

Leen15 commented 9 years ago

So there is no possibility for add a retrocompatibility on PUT method since lots of client doesn't yet support it for default? (like windows store apps, windows phone, android etc)

jguittard commented 9 years ago

What do you mean by retrocompatibility for PUT ? Again, if you want to update a resource with PUT, you need to provide unchanged properties + the one(s) you want to update. Let's take an example. Entity is : { id: 2 foo: "bar" baz: "fee" } You want to update with baz=woo.

With PATCH method you would send: { baz: "woo" }

With PUT method, you would send: { id: 2 foo: "bar" baz: "woo" } It's not an Apigility implementation, it's just the way HTTP protocol works. To use PUT, you need to send the whole resource set of properties, not just the ones you want to update.

Julien.

Le 14 mars 2015 à 12:50, Luca notifications@github.com a écrit :

So there is no possibility for add a retrocompatibility on PUT method since lots of client doesn't yet support it for default? (like windows store apps, windows phone, android etc)

— Reply to this email directly or view it on GitHub.

Leen15 commented 9 years ago

Ok, thanks for explanation!