Note that there are some explanatory texts on larger screens.

plurals
  1. POAmplify.js - CRUD-like urls
    primarykey
    data
    text
    <p>I am using <a href="http://amplifyjs.com/api/request/" rel="noreferrer">amplify.request</a>, and I would like to have CRUD-like URLs when sending data to and from the server. Here is an example:</p> <h3>Defining the resource</h3> <pre><code>resources = { "document_create" : ['/d/crud/', "POST"], "document_read" : ['/d/crud/{id}', "GET"], "document_update" : ['/d/crud/{id}', "PUT"], "document_delete" : ['/d/crud/{id}', "DELETE"] }; $.each(resources, function (resource, settings) { definition = { url : settings[0], type : settings[1], dataType: "json", // what comes back decoder : 'jsend', contentType: 'application/json' // what goes there }; amplify.request.define(resource, "ajax", definition); }); </code></pre> <h3>Employing the resource</h3> <pre><code>function make_request(resource, params, success_cb, error_cb) { if (this.is_post(resource)) { // this.is_post is a test, defined elsewhere, to see if this is a POST request params = JSON.stringify(params); } amplify.request( resourceId: resource data: params success: success_cb error: error_cb ); } </code></pre> <p>This works fine for <code>create</code> and <code>read</code> and `delete, like-so:</p> <pre><code>make_request('document_delete', {id: 1}, cb) </code></pre> <p>However, for <code>update</code>, since the content is being passed as JSON, the URL substitution does not occur as intended.</p> <p>Is there a way to take advantage of the URL substitution for <code>{id}</code> in the above scheme?</p> <p>The only alternative I can think of is to pass the data to the server URL-encoded. Unfortunately this is somewhat problematic, and I would prefer to be able to retain the use of CRUD-like URLs and saving with JSON formatted data, if that is possible.</p> <p>Thoughts would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload