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) »
  • is the rest interface really restufl
Pages: [1] 2

Author Topic: is the rest interface really restufl  (Read 2048 times)

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
is the rest interface really restufl
April 19, 2013, 01:26:14 am
so... I've got the backbonejs library to play very nicly with drupal 6 services module

and my mind turned back at long last to the civi V3 api - with great glee i'm might add

I'm just wondering if the restful interface the http metons get/push/post/delete etc

http://stackoverflow.com/questions/671118/what-exactly-is-restful-programming

I had a moment of realy excitement thinking about hook backbone right up to the innards of civicrm... but backbone expects a restful server... so do i need to write a wrapper? maybe something others could be interested in?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: is the rest interface really restufl
April 19, 2013, 01:51:44 am
REST is one name that means a bit of everything.

We don't support DELETE and PUT actions,  If you have a use case, it shouldn't be complicated to add.

... but I'd doubt it's needed for backbone, because browsers don't support them either.

Might check out what Tim and colemans did with backbone for the profile magic editor on 4.3.

For the rest, we are REST ;)

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

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: is the rest interface really restufl
April 19, 2013, 09:52:32 am
The wrapper is CRM.api() and it's pretty wonderful :)
Being more restful is something we probably should target for API v4, although as X mentioned, REST was conceived as an abstract theory, but putting it into practice in the real world tends to raise a lot of questions that the theory doesn't address.
Take a look in the js folder in Civi, esp at the crm.backbone.js and crm.designerapp.js files, and the related model and view files to see how we're doing it so far.
Also this will help you with some of the nitty gritty js-in-civi stuff: http://wiki.civicrm.org/confluence/display/CRMDOC43/Javascript+Reference
Try asking your question on the new CiviCRM help site.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: is the rest interface really restufl
April 19, 2013, 02:45:06 pm
Coleman - what version is that wrapper valid from?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: is the rest interface really restufl
April 19, 2013, 02:50:10 pm
4.2: cj().crmAPI()
4.3: CRM.api()
Also as of 4.3.1 it is quite easy to use CRM.api outside the context of a Civi page (i.e. in a drupal module, WP plugin, etc). Just do:
civicrm_initialize();
CRM_Core_Resources::singleton()->addCoreResources();
and then all our javascript magic will be at your fingertips.
Try asking your question on the new CiviCRM help site.

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: is the rest interface really restufl
April 19, 2013, 03:23:02 pm
you guys rock - so how do I do this?

and anyone got any comments along the lines "backbone??? you crazy?? use xyz intstead!"

or is backbonejs are reasonable choice?

btw updating  tags (maybe phone numbers and email) is obvious use case for DELETE

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: is the rest interface really restufl
April 19, 2013, 03:43:25 pm
Quote
Take a look in the js folder in Civi, esp at the crm.backbone.js

Erich - looks like Coleman has already been implementing backbone with Civi (albeit in 4.3) -
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: is the rest interface really restufl
April 19, 2013, 04:04:39 pm
Yes and I documented it a bit (well the concept anyway), check the bottom of http://wiki.civicrm.org/confluence/display/CRMDOC43/Javascript+Reference
Try asking your question on the new CiviCRM help site.

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: is the rest interface really restufl
April 20, 2013, 06:59:53 pm
great - so that's got to be the next thing for me to get my head around then

hopefully with out recent server upgrades I should be back up to recent revision of civi

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: is the rest interface really restufl
April 21, 2013, 02:45:21 am
Quote from: Erich Schulz on April 19, 2013, 03:23:02 pm
btw updating  tags (maybe phone numbers and email) is obvious use case for DELETE

Pretty much every entity type handles delete, the difference is that instead of doing a DELETE on example.org/civicrm/{entity}/42
you do a POST on example.org/civicrm/ajax/rest?entity={entity}&action=delete&id=42

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

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: is the rest interface really restufl
April 21, 2013, 03:31:57 pm
watched a one hour video on marionettejs last night - looks good... i was feeling a bit "undirected" with backbone... so something with some opinions would help

also checked my local install and couldn't find crm.backbone.js locally so wil fish around online for the current dev branch (I'll see what I can negotiate with our long-sufferening contractor)

but how about a thin layer between the drupal services module and the v3 api to do "proper rest" - ie using DELETE, PATCH etc?? rechecke the backbone docs and backbone definitely seems to use these

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: is the rest interface really restufl
April 21, 2013, 04:07:05 pm
Quote
couldn't find crm.backbone.js locally so wil fish around online for the current dev branch
You should upgrade to version 4.3. It is not in dev, it is a stable release.
Your project will be fruitless with an earlier version of Civi.
« Last Edit: April 21, 2013, 04:09:52 pm by Coleman Watts »
Try asking your question on the new CiviCRM help site.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: is the rest interface really restufl
April 22, 2013, 01:36:22 am
Quote from: Erich Schulz on April 21, 2013, 03:31:57 pm
but how about a thin layer between the drupal services module and the v3 api to do "proper rest" - ie using DELETE, PATCH etc?? rechecke the backbone docs and backbone definitely seems to use these

Still not sure what is your aim of using PATCH/PUT/DELETE http methods over the existing POST+ action param. Could you detail?

Anyway, if you want to add these new methods, I'd suggest you to patch civi directly, so whatever developed could end up being used with the other CMS too. My concern is that given how widely different the urls are between CMS (and some being not so nice looking), I'm not sure I see the benefit of handling extra http methods.

As backbone allows to adjust how the server api is called (eg. to override doSave or the sync method) it's easy to match what "native civi" offers. Basically, you just have to use CRM.api() and it will take care of setting the right params over the wire transparently.

Check out js/view/crm.designer.js to see how it was done for the profile.

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: is the rest interface really restufl
April 22, 2013, 02:41:33 pm
Erich - you can browse the 4.3 repository from here

https://github.com/civicrm/civicrm-core
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: is the rest interface really restufl
May 24, 2013, 07:28:49 pm
thanks Eileen will do

@Xavier... I guess just looking at a clean solution - was able to hook up backbone to the drupal services module with full CRUD verbs... (this is crustly old drupal 6!)

Backbone can cope with "legacy services" ... but v3 api is a bit young to be getting old isn't it?

but I wasn't aware civicrm already had a backbone extension so if that's done awesome but that still leaves all the other clients

I'm really looking forward to being able to hook into the v3 api!!!! am headiing to git hub right now

:-)

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • is the rest interface really restufl

This forum was archived on 2017-11-26.