Add createResource to HttpHypermediaClient
authorFrank Bessou <frank.bessou@logilab.fr>
Thu, 04 May 2017 17:16:27 +0200
changeset 179 fbb644088c11
parent 178 6d904376b32e
child 180 99abdceaf645
Add createResource to HttpHypermediaClient Named this way because we expect the server to return the location of the created resource.
src/components/Entity.js
src/services/hypermedia.js
--- a/src/components/Entity.js	Thu May 04 09:55:36 2017 +0200
+++ b/src/components/Entity.js	Thu May 04 17:16:27 2017 +0200
@@ -403,7 +403,7 @@
     }
 
     onSubmit({formData}) {
-        Api.createEntity(this.etype, formData)
+        HypermediaClient.createResource(`/${this.etype}/`, formData)
             .then(data => {
                 if (data.hasOwnProperty('errors')) {
                     // XXX better update formData to `.addError` inline...
--- a/src/services/hypermedia.js	Thu May 04 09:55:36 2017 +0200
+++ b/src/services/hypermedia.js	Thu May 04 17:16:27 2017 +0200
@@ -98,6 +98,17 @@
             });
     }
 
+    createResource(url, data) {
+        const options = {
+            method: 'POST',
+            headers: {
+                'Content-Type': 'application/json',
+            },
+            body: JSON.stringify(data),
+        };
+        return this.jsonFetch(url, options);
+    }
+
     updateResource(url, data) {
         const options = {
             method: 'PATCH',