@@ -41,13 +41,18 @@ interface FetchResourceOptions {
4141 * fetch through that server.
4242 */
4343 from ?: string ;
44+ method ?: 'GET' | 'POST' ;
45+ /** The body is only used combined with the `POST` method */
46+ body ?: ArrayBuffer | string ;
4447}
4548
46- interface HTTPResult {
49+ /** Contains one or more Resources */
50+ interface HTTPResourceResult {
4751 resource : Resource ;
4852 createdResources : Resource [ ] ;
4953}
5054
55+ /** Contains a `fetch` instance, provides methods to GET and POST several types */
5156export class Client {
5257 private __fetchOverride ?: typeof fetch ;
5358
@@ -110,8 +115,8 @@ export class Client {
110115 public async fetchResourceHTTP (
111116 subject : string ,
112117 opts : FetchResourceOptions = { } ,
113- ) : Promise < HTTPResult > {
114- const { signInfo, from } = opts ;
118+ ) : Promise < HTTPResourceResult > {
119+ const { signInfo, from, body : bodyReq } = opts ;
115120 let createdResources : Resource [ ] = [ ] ;
116121 const parser = new JSONADParser ( ) ;
117122 let resource = new Resource ( subject ) ;
@@ -143,6 +148,8 @@ export class Client {
143148
144149 const response = await this . fetch ( url , {
145150 headers : requestHeaders ,
151+ method : bodyReq ? 'POST' : 'GET' ,
152+ body : bodyReq ,
146153 } ) ;
147154 const body = await response . text ( ) ;
148155
@@ -256,16 +263,30 @@ export class Client {
256263 return resources ;
257264 }
258265
259- /** Instructs an Atomic Server to fetch a URL and get its JSON-AD */
260- public async importJsonAdUrl (
261- /** The URL of the JSON-AD to import */
262- jsonAdUrl : string ,
263- /** Importer URL. Servers tend to have one at `example.com/import` */
264- importerUrl : string ,
265- ) : Promise < HTTPResult > {
266- const url = new URL ( importerUrl ) ;
267- url . searchParams . set ( 'url' , jsonAdUrl ) ;
268-
269- return this . fetchResourceHTTP ( url . toString ( ) ) ;
270- }
266+ // /** Instructs an Atomic Server to fetch a URL and get its JSON-AD */
267+ // public async importJsonAdUrl(
268+ // /** The URL of the JSON-AD to import */
269+ // jsonAdUrl: string,
270+ // /** Importer URL. Servers tend to have one at `example.com/import` */
271+ // importerUrl: string,
272+ // ): Promise<HTTPResourceResult> {
273+ // const url = new URL(importerUrl);
274+ // url.searchParams.set('url', jsonAdUrl);
275+
276+ // return this.fetchResourceHTTP(url.toString());
277+ // }
278+
279+ // /** Instructs an Atomic Server to fetch a URL and get its JSON-AD */
280+ // public async importJsonAdString(
281+ // /** The JSON-AD to import */
282+ // jsonAdString: string,
283+ // /** Importer URL. Servers tend to have one at `example.com/import` */
284+ // importerUrl: string,
285+ // ): Promise<HTTPResourceResult> {
286+ // const url = new URL(importerUrl);
287+
288+ // return this.fetchResourceHTTP(url.toString(), {
289+ // body: jsonAdString,
290+ // });
291+ // }
271292}
0 commit comments