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,
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:
Below is one example that does not tell us which field is optional:
HTH
Regards,
yantothen
blog.ipcraft.net
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:
Below is one example that does not tell us which field is optional:
HTH
Regards,
yantothen
blog.ipcraft.net
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:
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/
Regards,