VMware Networking Community
cnrz
Expert
Expert
Jump to solution

Rest API Post and Put Difference

In the NSX Rest API Documentation POST  and PUT are defined as following:

REST defines the use of POST, GET, PUT and DELETE to implement CRUD (create,

read, update and delete) operations. The below table describes various HTTP verbs and

their corresponding operations; the context used is NSX as the system being utilized.

HTTP “Verbs”

POST --> Create an NSX object (e.g. logical switch)

GET -->  Retrieve data about a single NSX object or multiple objects

PUT -->  Modify the properties of an already existing NSX object

DELETE --> Remove an NSX object


Some examples PUT may be used for creating, ang POST may be used for modifying. More general context some pages have different approaches. For NSX API, how do these commands differ for creating or updating Objects?


For example instead of specifying every field or property of the object, if only IP address 172.16.10.10 is given omitting Port, Protocol and Level fields does the command create the syslog server with default values for other fields as 514, UDP and INFO?


Similarly if only the IP address need to be modified again every other fields that need no modification need to be specified?

<controllerSyslogServer>

<syslogServer>172.16.10.10</syslogServer>

<port>514</port>

<protocol>UDP</protocol>

<level>INFO</level>

</controllerSyslogServer>

http://stretch-cloud.info/2015/01/configuring-syslog-nsx-vsphere-controller-using-rest-api/

http://cloudmaniac.net/nsx-syslog-configuration-api/

https://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/

https://stormpath.com/blog/put-or-post

Thanks in Advance,

0 Kudos
1 Solution

Accepted Solutions
yantothen
Enthusiast
Enthusiast
Jump to solution

Hi cnrz,

POST or PUT

As I know, POST is always used for creating/adding object and PUT is used for modifying object.

For the particular example (Adding Syslog server on NSX Controller): there is no PUT operation for this DisplayName (nsxControllerSyslog).

We are only provided with:

- POST: Add syslog exporter for the controller

- DELETE: Delete the syslog exporter from the controller

- GET: Retrieve the syslog exporter from the controller

Since there is no PUT operation that is applicable for this, we can't, for example change the syslog server IP address or the port number.

We need to DELETE and POST again.

Another example is: we add new firewall rules with POST and modify the firewall rules with PUT.

Which Fields are Optional?

Regarding whether we need to specify all fields in the XML body, I believe this should be the job of the NSX RAML API specification file (nsxvapi.raml) to document all these information.

Unfortunately, not all fields are explicitly mentioned/described whether they are optional or not.


Below is one example that tells us which field is optional:

nsxraml-example1.png

Below is one example that does not tell us which field is optional:

nsxraml-example2.png

HTH

Regards,

yantothen

blog.ipcraft.net

View solution in original post

2 Replies
yantothen
Enthusiast
Enthusiast
Jump to solution

Hi cnrz,

POST or PUT

As I know, POST is always used for creating/adding object and PUT is used for modifying object.

For the particular example (Adding Syslog server on NSX Controller): there is no PUT operation for this DisplayName (nsxControllerSyslog).

We are only provided with:

- POST: Add syslog exporter for the controller

- DELETE: Delete the syslog exporter from the controller

- GET: Retrieve the syslog exporter from the controller

Since there is no PUT operation that is applicable for this, we can't, for example change the syslog server IP address or the port number.

We need to DELETE and POST again.

Another example is: we add new firewall rules with POST and modify the firewall rules with PUT.

Which Fields are Optional?

Regarding whether we need to specify all fields in the XML body, I believe this should be the job of the NSX RAML API specification file (nsxvapi.raml) to document all these information.

Unfortunately, not all fields are explicitly mentioned/described whether they are optional or not.


Below is one example that tells us which field is optional:

nsxraml-example1.png

Below is one example that does not tell us which field is optional:

nsxraml-example2.png

HTH

Regards,

yantothen

blog.ipcraft.net

cnrz
Expert
Expert
Jump to solution

Hi yantothen,

Thanks for reply, it is useful that you explained it may change according to which object is trying to be modified or created, so the API document specifies how/what can be done. So there is no general  standart rule and it would be better to check before preparation of the XML Code. I think also this may change for API version as well adding additional to the API Code.

About the optional and mandatory fields, this may be important when you try to configure a code other than exmaples on the REST API guide. If optional parameters are not exactly known, then for creating or changing a single parameter, all the related properties may need to be specified (which is difficult to know if not explicitly documented). Troubleshooting depends on the documentation, so again then what is optional or not depends on the object

For NSX Manger syslog example as below, PUT is possible,  different than  NSX Controller:

https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2092...

Configure syslog servers (for NSX  Manager)

Request:
PUT https://<nsxmgr-ip>/api/1.0/appliance-management/system/syslogserver
Request Body
<syslogserver>
<syslogServer></syslogServer>
<port></port>
<protocol></protocol>
</syslogserver>

PUT is also possible for NSX Edge:

http://blog.tsugliani.fr/vcloud/playing-with-rest-apis-and-httpie-vcns-api/

Syslog_Edge_Rest_API.jpg

Regards,

0 Kudos