CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • rest interface (more rant on the method;)
Pages: [1]

Author Topic: rest interface (more rant on the method;)  (Read 5498 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
rest interface (more rant on the method;)
November 13, 2008, 12:47:51 pm
Hi,

The expected method is get. This is bad bad bad for every action that modify the datas (eg add delete modify methods), that should be post.

Any idea to makes it better ? Shouldn't we go to a much more defined list of actions, and stick to it ?

eg, that's always entity/action

action is :
search (or list ?)
read (or get ?)
delete
add
modify

+ more specific ones if needed ?
of course, only the first two onces are get.

Any suggestion to solve my get/post issue without either having to define by hand every action, or without having to go api/v3 ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

acrosman

  • Guest
Re: rest interface (more rant on the method;)
November 14, 2008, 06:50:58 am
In the long run I agree that we should move to a better breakdown of the commands and the methods.  When I extended the old experimental/proof of concept REST interface, I just wanted to find a way to expose the whole CiviCRM API to the interface.  At the time there was a small selection of functions exposed, and I needed to develop a better way to check for the function.  I'm certainly not going to defend this as the best way to get the job done.

You raised two issues that I am also worried about.  First, how do we do this without maintain a list of all the functions, and second do we do this in v2 or v3.

From a quick review of the API methods the naming is pretty consistent, each section has a subset of: add, get, search, delete, and remove, commands (there might be a couple more, but at any rate the list appears to be fairly short).  We could map those to the request methods: get/search -> GET, add -> POST etc.  It doesn't look like it would be too onerous.  I'd be inclined to leave a catch-all that defaulted predictably in case new commands get added that introduce a new word.

As for versions, I think I'd like to see v2 continue to support everything coming in over GET even if we declare some of those commands depreciated for v3.  We could start to allow some commands to come in by other methods, but I'd like to see the support of all GET continue for a little while longer.

Do we want to use methods other than GET and POST?  Should we also allow PUT and DELETE?  My understanding (which is limited) is that Apache often needs additional configuration to make PUT and DELETE work properly for REST interfaces.  Is that added a burden that some configurations wont be able to overcome because of their hosting environments?

Aaron

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: rest interface (more rant on the method;)
November 14, 2008, 12:42:46 pm
Quote from: acrosman on November 14, 2008, 06:50:58 am
In the long run I agree that we should move to a better breakdown of the commands and the methods.  When I extended the old experimental/proof of concept REST interface, I just wanted to find a way to expose the whole CiviCRM API to the interface.  At the time there was a small selection of functions exposed, and I needed to develop a better way to check for the function.  I'm certainly not going to defend this as the best way to get the job done.
And that' s been very useful an appreciated. For the various ongoing discussions, even so we are going to focus on the things that have to be improve, I'm not loosing the fact that something that doesn't work as well as one can hope is still miles away of nothing ;)

Quote from: acrosman on November 14, 2008, 06:50:58 am
You raised two issues that I am also worried about.  First, how do we do this without maintain a list of all the functions, and second do we do this in v2 or v3.

Quote from: acrosman on November 14, 2008, 06:50:58 am
From a quick review of the API methods the naming is pretty consistent, each section has a subset of: add, get, search, delete, and remove, commands (there might be a couple more, but at any rate the list appears to be fairly short).  We could map those to the request methods: get/search -> GET, add -> POST etc.  It doesn't look like it would be too onerous.  I'd be inclined to leave a catch-all that defaulted predictably in case new commands get added that introduce a new word.
Makes sense

Quote from: acrosman on November 14, 2008, 06:50:58 am
As for versions, I think I'd like to see v2 continue to support everything coming in over GET even if we declare some of those commands depreciated for v3.  We could start to allow some commands to come in by other methods, but I'd like to see the support of all GET continue for a little while longer.

Well right now the tag ajax thingie doesn't use post, only get. I'll check if we can make the rest accepts both post and get and try to use post for the destructive methods.

Quote from: acrosman on November 14, 2008, 06:50:58 am
Do we want to use methods other than GET and POST?  Should we also allow PUT and DELETE?  My understanding (which is limited) is that Apache often needs additional configuration to make PUT and DELETE work properly for REST interfaces.  Is that added a burden that some configurations wont be able to overcome because of their hosting environments?

Not sure, and we're using lighttpd, but I don't see as much of a benefit as only having a clear separation between the non desctructive (get) and destructive ones (post)
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

acrosman

  • Guest
Re: rest interface (more rant on the method;)
November 17, 2008, 11:29:00 am
Quote from: xavier on November 14, 2008, 12:42:46 pm

Well right now the tag ajax thingie doesn't use post, only get. I'll check if we can make the rest accepts both post and get and try to use post for the destructive methods.

My guess right now is the REST interface only accepts GET requests (that's certainly all I've ever tested).  It would be simple enough to get the parameters handled correctly, the hard part will be picking which commands have to come over which methods.  As I said before that shouldn't be TOO bad.

What really needs to happen is we need to get moving on some actual code to get things to Lobo before the code freeze goes into effect.

We need the new authentication method written, and adding on the ability for at least some commands to come in over POST requests.

Aaron

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: rest interface (more rant on the method;)
November 18, 2008, 11:56:55 am
You are right,

I'll change to handle _REQUEST instead of _GET

As for the what is post is what is get, I think we need to do a proper mapping of what are the entity/actions. Let me look at your wiki page and see if I see a patern.

Any suggestion more than welcome...

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

acrosman

  • Guest
Re: rest interface (more rant on the method;)
November 18, 2008, 01:59:44 pm
For more suggestions see the new thread at:
http://forum.civicrm.org/index.php?topic=5644

Granted that looks like a whole new set of suggestions that need to be considered. 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: rest interface (more rant on the method;)
November 19, 2008, 12:10:15 am
Interesting post.

Not sure about the DELETE/PUT methods, it looks like the right http things to do, but I'm not aware of any javascript/ajax library that can handle them, at least easily.

I think that if having POST + $_post['action'] is allowing the rest interface to be called both from another server and from a js interface, that is better (from a practical point of view, not a theorical one).

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

acrosman

  • Guest
Re: rest interface (more rant on the method;)
November 19, 2008, 04:01:17 am
Quote from: xavier on November 19, 2008, 12:10:15 am
Interesting post.

Not sure about the DELETE/PUT methods, it looks like the right http things to do, but I'm not aware of any javascript/ajax library that can handle them, at least easily.

I think that if having POST + $_post['action'] is allowing the rest interface to be called both from another server and from a js interface, that is better (from a practical point of view, not a theorical one).

X+

You can do PUT and DELETE in Javascript:
http://www.wynia.org/wordpress/2007/03/18/not-just-get-and-post-http-put-and-delete-with-javascript/
It's just not something people talk about a whole lot.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: rest interface (more rant on the method;)
November 19, 2008, 04:32:33 am
Didn't know, thanks.

For what I understood, you can do that from javascript, but not from "regular" html forms, that only talks get or post.
Might be a limitation on some cases, eg. if using the rest interface as a backend for ajax stuff  ?

This being said, the rest interface of the big boys (eg amazon S3) does use at least the delete method. Has someone a hands on experience of an DELETE+PUT method ? Any problem in any specific case ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

acrosman

  • Guest
Re: rest interface (more rant on the method;)
November 22, 2008, 10:24:20 am
My only concern about adding the other two verbs is making sure we're not causing a problem for server support.  I've read mixed things about default configurations on Apache (I haven't read anything about other servers), which I suspect means we'll need to make sure there are directions that make it clear what to check for in their server's configuration.

If everyone is clear it's not an issue at that level, I don't really see a problem with it.

Aaron

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: rest interface (more rant on the method;)
November 23, 2008, 06:30:58 am

how about in 2.2 we introduce POST and in 2.3 / 3.0, we introduce DELETE/PUT

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

acrosman

  • Guest
Re: rest interface (more rant on the method;)
November 23, 2008, 01:41:13 pm
That sounds like a good compromise to me.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • rest interface (more rant on the method;)

This forum was archived on 2017-11-26.