Foreman API many-to-many RESTful

I would like to get people's feedback on how to best implement many-to-many relationships in a RESTful way.

I just pushed a pull request that allows users to add and remove puppetclasses from a host or hostgroup using the API. https://github.com/theforeman/foreman/pull/424

Option #1) Do not expose the join table in the API and use PUT to add a new puppetclass (this is the option that I chose)

PUT /api/hosts/:id/puppetclasses/:id
PUT /api/hostgroups/:id/puppetclasses/:id

curl -u admin:secret -H "Content-Type:application/json" -H "Accept:application/json,version=2" -X PUT -d "{}" http://0.0.0.0:3000/api/hosts/182/puppetclasses/17

Notice that no data is passed beyond what is in the URL.

DELETE /api/hosts/:id/puppetclasses/:id
DELETE /api/hostgroups/:id/puppetclasses/:id

curl -u admin:secret -H "Content-Type:application/json" -H "Accept:application/json,version=2" -X DELETE http://0.0.0.0:3000/api/hosts/182/puppetclasses/17

Option #2) Expose the join table in the API

POST /api/hosts/:id/host_classes
POST /api/hostgroups/:id/hostgroup_classes

DELETE /api/hosts/:id/host_classes
DELETE /api/hostgroups/:id/hostgroup_classes

curl -u admin:secret -H "Content-Type:application/json" -H "Accept:application/json,version=2" -X POST -d "{"host_class":{"puppetclass_id":"17"}}" http://0.0.0.0:3000/api/hosts/182/host_classes

I like option #1 better. Any feedback?

Regards,

Joseph

Correction. The pull request is https://github.com/theforeman/foreman/pull/432

··· ----- Original Message ----- From: "Joseph Magen" To: "foreman-dev" , katello-devel@redhat.com Sent: Monday, February 25, 2013 4:29:17 PM Subject: [foreman-dev] Foreman API many-to-many RESTful

I would like to get people’s feedback on how to best implement many-to-many relationships in a RESTful way.

I just pushed a pull request that allows users to add and remove puppetclasses from a host or hostgroup using the API. https://github.com/theforeman/foreman/pull/424

Option #1) Do not expose the join table in the API and use PUT to add a new puppetclass (this is the option that I chose)

PUT /api/hosts/:id/puppetclasses/:id
PUT /api/hostgroups/:id/puppetclasses/:id

curl -u admin:secret -H “Content-Type:application/json” -H “Accept:application/json,version=2” -X PUT -d “{}” http://0.0.0.0:3000/api/hosts/182/puppetclasses/17

Notice that no data is passed beyond what is in the URL.

DELETE /api/hosts/:id/puppetclasses/:id
DELETE /api/hostgroups/:id/puppetclasses/:id

curl -u admin:secret -H “Content-Type:application/json” -H “Accept:application/json,version=2” -X DELETE http://0.0.0.0:3000/api/hosts/182/puppetclasses/17

Option #2) Expose the join table in the API

POST /api/hosts/:id/host_classes
POST /api/hostgroups/:id/hostgroup_classes

DELETE /api/hosts/:id/host_classes
DELETE /api/hostgroups/:id/hostgroup_classes

curl -u admin:secret -H “Content-Type:application/json” -H “Accept:application/json,version=2” -X POST -d “{“host_class”:{“puppetclass_id”:“17”}}” http://0.0.0.0:3000/api/hosts/182/host_classes

I like option #1 better. Any feedback?

Regards,

Joseph


You received this message because you are subscribed to the Google Groups “foreman-dev” group.
To unsubscribe from this group and stop receiving emails from it, send an email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out .