Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example with POST #58

Merged
merged 4 commits into from
Aug 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,46 @@ <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
<a data-cite="WebShare#dom-sharedata">ShareData</a> members. This
example also shows a share target that receives data as a
<code>POST</code> request, which should be the case if the request
causes an immediate side effect.
</p>
<pre class="example json" title="manifest.webmanifest">
{
"name": "Bookmark",
"share_target": {
"action": "/bookmark",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"url": "link"
}
}
}
</pre>
<p>
The shared information might be read by a <a data-cite=
"service-workers-1#service-worker-concept">service worker</a>, rather
than being sent over the network to the server.
</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') || '';
saveBookmark(link);
return new Response('Bookmark saved: ' + 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 +365,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