Skip to content

Commit

Permalink
Example with POST
Browse files Browse the repository at this point in the history
We now have an example of receiving a POST, and state POST semantics.

resolves w3c#57
  • Loading branch information
ericwilligers committed Aug 6, 2018
1 parent 8dc8b6d commit 7626171
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,40 @@ <h2>
shared. If the ShareData contains no information for a given member,
the query parameter is omitted.
</p>
<p>
A share target might only be interested in a subset of the ShareData
members.
</p>
<pre class="example json" title="manifest.webmanifest">
{
"name": "Bookmark",
"share_target": {
"action": "bookmark.html",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"url": "link"
}
}
}
</pre>
<p>
The shared information might be read by a service worker.
</p>
<pre class="example javascript" title="sw.js">
self.addEventListener('fetch', event =&gt; {
if (event.request.method !== 'POST') {
event.respondWith(fetch(event.request));
return;
}

event.respondWith((async () =&gt; {
const formData = await event.request.formData();
const link = formData.get('link') || '';
return new Response('Shared link: ' + link);
})());
});
</pre>
<p>
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
Expand Down Expand Up @@ -325,6 +359,12 @@ <h3>
"https://tools.ietf.org/html/rfc7231#section-4">method</a> for the
<a data-link-for="web share targets">web share target</a>.
</p>
<p class="note">
A use case for <code>GET</code> 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,
<code>POST</code> requests should be used.
</p>
<p>
The <dfn>enctype</dfn> member specifies how the share data is encoded
in the body of a <code>POST</code> request. It is ignored when
Expand Down

0 comments on commit 7626171

Please sign in to comment.