Adam Sobotka Adam Sobotka - 1 year ago 83
reST (reStructuredText) Question

Polymer REST backend

I have a backend written in golang exposing /api/list interface. It returns lists when called from GET and create new list when it receive POST with parameters.
I can read it with standard core-ajax element, there is a huge amount of examples to do that.

What I didn't understood is what should I do, when I want to create new element through POST? I read the documentation and searched for sample code for half day, can you point me to right direction?
Ok, thanks for help, it was really only bad format of json I was sending. There is still dark cloud in my mind telling that I misunderstood something from conceptual view. Is this:

<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/core-ajax/core-ajax.html">

<polymer-element name="channels-service" attributes="channels">
:host {
display: none;
<core-ajax id="ch_load"
<core-ajax id="ch_update"
Polymer('channels-service', {
created: function() {
this.channels = [];
channelsLoaded: function() {
// Make a copy of the loaded data
this.channels = this.$.ch_load.response.slice(0);
newChannel: function(ch_name) {
// this.$.ch_update.body = "ch_name";
this.$.ch_update.body = '{"Name":"pitchalist2"}'
channelsUpdated: function() {

correctly written data layer? It looks very counterintuitive to me and in examples using local data storage it works way easier.

Answer Source

You can send a POST request by setting the method attribute (method="POST") and the body attribute (body='{"my":"data"}'). Indeed you need a second iron-ajax element for this request.

See the attributes section in the core-ajax documentation.