@@ -168,6 +168,46 @@ <h2>
168
168
shared. If the ShareData contains no information for a given member,
169
169
the query parameter is omitted.
170
170
</ p >
171
+ < p >
172
+ A share target might only be interested in a subset of the
173
+ < a data-cite ="WebShare#dom-sharedata "> ShareData</ a > members. This
174
+ example also shows a share target that receives data as a
175
+ < code > POST</ code > request, which should be the case if the request
176
+ causes an immediate side effect.
177
+ </ p >
178
+ < pre class ="example json " title ="manifest.webmanifest ">
179
+ {
180
+ "name": "Bookmark",
181
+ "share_target": {
182
+ "action": "/bookmark",
183
+ "method": "POST",
184
+ "enctype": "multipart/form-data",
185
+ "params": {
186
+ "url": "link"
187
+ }
188
+ }
189
+ }
190
+ </ pre >
191
+ < p >
192
+ The shared information might be read by a < a data-cite =
193
+ "service-workers-1#service-worker-concept "> service worker</ a > , rather
194
+ than being sent over the network to the server.
195
+ </ p >
196
+ < pre class ="example javascript " title ="sw.js ">
197
+ self.addEventListener('fetch', event => {
198
+ if (event.request.method !== 'POST') {
199
+ event.respondWith(fetch(event.request));
200
+ return;
201
+ }
202
+
203
+ event.respondWith((async () => {
204
+ const formData = await event.request.formData();
205
+ const link = formData.get('link') || '';
206
+ saveBookmark(link);
207
+ return new Response('Bookmark saved: ' + link);
208
+ })());
209
+ });
210
+ </ pre >
171
211
< p >
172
212
How the handler deals with the shared data is at the handler's
173
213
discretion, and will generally depend on the type of app. Here are some
@@ -325,6 +365,12 @@ <h3>
325
365
"https://tools.ietf.org/html/rfc7231#section-4 "> method</ a > for the
326
366
< a data-link-for ="web share targets "> web share target</ a > .
327
367
</ p >
368
+ < p class ="note ">
369
+ A use case for < code > GET</ code > requests is when the share target
370
+ drafts a message for subsequent user approval. If the share target
371
+ performs a side-effect without any user interaction,
372
+ < code > POST</ code > requests should be used.
373
+ </ p >
328
374
< p >
329
375
The < dfn > enctype</ dfn > member specifies how the share data is encoded
330
376
in the body of a < code > POST</ code > request. It is ignored when
0 commit comments