From 7626171b05118449949e18f9b52503047d04e666 Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Tue, 31 Jul 2018 17:17:51 +1000 Subject: [PATCH] Example with POST We now have an example of receiving a POST, and state POST semantics. resolves #57 --- index.html | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/index.html b/index.html index f31644a..69d9836 100644 --- a/index.html +++ b/index.html @@ -168,6 +168,40 @@

shared. If the ShareData contains no information for a given member, the query parameter is omitted.

+

+ A share target might only be interested in a subset of the ShareData + members. +

+
+{
+  "name": "Bookmark",
+  "share_target": {
+    "action": "bookmark.html",
+    "method": "POST",
+    "enctype": "multipart/form-data",
+    "params": {
+      "url": "link"
+    }
+  }
+}
+
+

+ The shared information might be read by a service worker. +

+
+self.addEventListener('fetch', event => {
+  if (event.request.method !== 'POST') {
+    event.respondWith(fetch(event.request));
+    return;
+  }
+
+  event.respondWith((async () => {
+    const formData = await event.request.formData();
+    const link = formData.get('link') || '';
+    return new Response('Shared link: ' + link);
+  })());
+});
+

How the handler deals with the shared data is at the handler's discretion, and will generally depend on the type of app. Here are some @@ -325,6 +359,12 @@

"https://tools.ietf.org/html/rfc7231#section-4">method for the web share target.

+

+ A use case for GET requests is when the share target + drafts a message for subsequent user approval. If the share target + performs a side-effect without any user interaction, + POST requests should be used. +

The enctype member specifies how the share data is encoded in the body of a POST request. It is ignored when