@@ -86,6 +86,31 @@ default APIResponse delete(String url) {
8686 * Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
8787 * context cookies from the response. The method will automatically follow redirects.
8888 *
89+ * <p> JSON objects can be passed directly to the request:
90+ * <pre>{@code
91+ * Map<String, Object> data = new HashMap();
92+ * data.put("title", "Book Title");
93+ * data.put("body", "John Doe");
94+ * request.fetch("https://example.com/api/createBook", RequestOptions.create().setMethod("post").setData(data));
95+ * }</pre>
96+ *
97+ * <p> The common way to send file(s) in the body of a request is to encode it as form fields with {@code multipart/form-data}
98+ * encoding. You can achieve that with Playwright API like this:
99+ * <pre>{@code
100+ * // Pass file path to the form data constructor:
101+ * Path file = Paths.get("team.csv");
102+ * APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
103+ * RequestOptions.create().setMethod("post").setMultipart(
104+ * FormData.create().set("fileField", file)));
105+ *
106+ * // Or you can pass the file content directly as FilePayload object:
107+ * FilePayload filePayload = new FilePayload("f.js", "text/javascript",
108+ * "console.log(2022);".getBytes(StandardCharsets.UTF_8));
109+ * APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
110+ * RequestOptions.create().setMethod("post").setMultipart(
111+ * FormData.create().set("fileField", filePayload)));
112+ * }</pre>
113+ *
89114 * @param urlOrRequest Target URL or Request to get all parameters from.
90115 */
91116 default APIResponse fetch (String urlOrRequest ) {
@@ -95,6 +120,31 @@ default APIResponse fetch(String urlOrRequest) {
95120 * Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
96121 * context cookies from the response. The method will automatically follow redirects.
97122 *
123+ * <p> JSON objects can be passed directly to the request:
124+ * <pre>{@code
125+ * Map<String, Object> data = new HashMap();
126+ * data.put("title", "Book Title");
127+ * data.put("body", "John Doe");
128+ * request.fetch("https://example.com/api/createBook", RequestOptions.create().setMethod("post").setData(data));
129+ * }</pre>
130+ *
131+ * <p> The common way to send file(s) in the body of a request is to encode it as form fields with {@code multipart/form-data}
132+ * encoding. You can achieve that with Playwright API like this:
133+ * <pre>{@code
134+ * // Pass file path to the form data constructor:
135+ * Path file = Paths.get("team.csv");
136+ * APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
137+ * RequestOptions.create().setMethod("post").setMultipart(
138+ * FormData.create().set("fileField", file)));
139+ *
140+ * // Or you can pass the file content directly as FilePayload object:
141+ * FilePayload filePayload = new FilePayload("f.js", "text/javascript",
142+ * "console.log(2022);".getBytes(StandardCharsets.UTF_8));
143+ * APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
144+ * RequestOptions.create().setMethod("post").setMultipart(
145+ * FormData.create().set("fileField", filePayload)));
146+ * }</pre>
147+ *
98148 * @param urlOrRequest Target URL or Request to get all parameters from.
99149 * @param params Optional request parameters.
100150 */
@@ -103,6 +153,31 @@ default APIResponse fetch(String urlOrRequest) {
103153 * Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
104154 * context cookies from the response. The method will automatically follow redirects.
105155 *
156+ * <p> JSON objects can be passed directly to the request:
157+ * <pre>{@code
158+ * Map<String, Object> data = new HashMap();
159+ * data.put("title", "Book Title");
160+ * data.put("body", "John Doe");
161+ * request.fetch("https://example.com/api/createBook", RequestOptions.create().setMethod("post").setData(data));
162+ * }</pre>
163+ *
164+ * <p> The common way to send file(s) in the body of a request is to encode it as form fields with {@code multipart/form-data}
165+ * encoding. You can achieve that with Playwright API like this:
166+ * <pre>{@code
167+ * // Pass file path to the form data constructor:
168+ * Path file = Paths.get("team.csv");
169+ * APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
170+ * RequestOptions.create().setMethod("post").setMultipart(
171+ * FormData.create().set("fileField", file)));
172+ *
173+ * // Or you can pass the file content directly as FilePayload object:
174+ * FilePayload filePayload = new FilePayload("f.js", "text/javascript",
175+ * "console.log(2022);".getBytes(StandardCharsets.UTF_8));
176+ * APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
177+ * RequestOptions.create().setMethod("post").setMultipart(
178+ * FormData.create().set("fileField", filePayload)));
179+ * }</pre>
180+ *
106181 * @param urlOrRequest Target URL or Request to get all parameters from.
107182 */
108183 default APIResponse fetch (Request urlOrRequest ) {
@@ -112,6 +187,31 @@ default APIResponse fetch(Request urlOrRequest) {
112187 * Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
113188 * context cookies from the response. The method will automatically follow redirects.
114189 *
190+ * <p> JSON objects can be passed directly to the request:
191+ * <pre>{@code
192+ * Map<String, Object> data = new HashMap();
193+ * data.put("title", "Book Title");
194+ * data.put("body", "John Doe");
195+ * request.fetch("https://example.com/api/createBook", RequestOptions.create().setMethod("post").setData(data));
196+ * }</pre>
197+ *
198+ * <p> The common way to send file(s) in the body of a request is to encode it as form fields with {@code multipart/form-data}
199+ * encoding. You can achieve that with Playwright API like this:
200+ * <pre>{@code
201+ * // Pass file path to the form data constructor:
202+ * Path file = Paths.get("team.csv");
203+ * APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
204+ * RequestOptions.create().setMethod("post").setMultipart(
205+ * FormData.create().set("fileField", file)));
206+ *
207+ * // Or you can pass the file content directly as FilePayload object:
208+ * FilePayload filePayload = new FilePayload("f.js", "text/javascript",
209+ * "console.log(2022);".getBytes(StandardCharsets.UTF_8));
210+ * APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
211+ * RequestOptions.create().setMethod("post").setMultipart(
212+ * FormData.create().set("fileField", filePayload)));
213+ * }</pre>
214+ *
115215 * @param urlOrRequest Target URL or Request to get all parameters from.
116216 * @param params Optional request parameters.
117217 */
@@ -121,6 +221,13 @@ default APIResponse fetch(Request urlOrRequest) {
121221 * response. The method will populate request cookies from the context and update context cookies from the response. The
122222 * method will automatically follow redirects.
123223 *
224+ * <p> Request parameters can be configured with {@code params} option, they will be serialized into the URL search parameters:
225+ * <pre>{@code
226+ * request.get("https://example.com/api/getText", RequestOptions.create()
227+ * .setQueryParam("isbn", "1234")
228+ * .setQueryParam("page", 23));
229+ * }</pre>
230+ *
124231 * @param url Target URL.
125232 */
126233 default APIResponse get (String url ) {
@@ -131,6 +238,13 @@ default APIResponse get(String url) {
131238 * response. The method will populate request cookies from the context and update context cookies from the response. The
132239 * method will automatically follow redirects.
133240 *
241+ * <p> Request parameters can be configured with {@code params} option, they will be serialized into the URL search parameters:
242+ * <pre>{@code
243+ * request.get("https://example.com/api/getText", RequestOptions.create()
244+ * .setQueryParam("isbn", "1234")
245+ * .setQueryParam("page", 23));
246+ * }</pre>
247+ *
134248 * @param url Target URL.
135249 * @param params Optional request parameters.
136250 */
@@ -178,6 +292,39 @@ default APIResponse patch(String url) {
178292 * response. The method will populate request cookies from the context and update context cookies from the response. The
179293 * method will automatically follow redirects.
180294 *
295+ * <p> JSON objects can be passed directly to the request:
296+ * <pre>{@code
297+ * Map<String, Object> data = new HashMap();
298+ * data.put("title", "Book Title");
299+ * data.put("body", "John Doe");
300+ * request.post("https://example.com/api/createBook", RequestOptions.create().setData(data));
301+ * }</pre>
302+ *
303+ * <p> To send form data to the server use {@code form} option. Its value will be encoded into the request body with
304+ * {@code application/x-www-form-urlencoded} encoding (see below how to use {@code multipart/form-data} form encoding to send files):
305+ * <pre>{@code
306+ * request.post("https://example.com/api/findBook", RequestOptions.create().setForm(
307+ * FormData.create().set("title", "Book Title").set("body", "John Doe")
308+ * ));
309+ * }</pre>
310+ *
311+ * <p> The common way to send file(s) in the body of a request is to upload them as form fields with {@code multipart/form-data}
312+ * encoding. You can achieve that with Playwright API like this:
313+ * <pre>{@code
314+ * // Pass file path to the form data constructor:
315+ * Path file = Paths.get("team.csv");
316+ * APIResponse response = request.post("https://example.com/api/uploadTeamList",
317+ * RequestOptions.create().setMultipart(
318+ * FormData.create().set("fileField", file)));
319+ *
320+ * // Or you can pass the file content directly as FilePayload object:
321+ * FilePayload filePayload = new FilePayload("f.js", "text/javascript",
322+ * "console.log(2022);".getBytes(StandardCharsets.UTF_8));
323+ * APIResponse response = request.post("https://example.com/api/uploadTeamList",
324+ * RequestOptions.create().setMultipart(
325+ * FormData.create().set("fileField", filePayload)));
326+ * }</pre>
327+ *
181328 * @param url Target URL.
182329 */
183330 default APIResponse post (String url ) {
@@ -188,6 +335,39 @@ default APIResponse post(String url) {
188335 * response. The method will populate request cookies from the context and update context cookies from the response. The
189336 * method will automatically follow redirects.
190337 *
338+ * <p> JSON objects can be passed directly to the request:
339+ * <pre>{@code
340+ * Map<String, Object> data = new HashMap();
341+ * data.put("title", "Book Title");
342+ * data.put("body", "John Doe");
343+ * request.post("https://example.com/api/createBook", RequestOptions.create().setData(data));
344+ * }</pre>
345+ *
346+ * <p> To send form data to the server use {@code form} option. Its value will be encoded into the request body with
347+ * {@code application/x-www-form-urlencoded} encoding (see below how to use {@code multipart/form-data} form encoding to send files):
348+ * <pre>{@code
349+ * request.post("https://example.com/api/findBook", RequestOptions.create().setForm(
350+ * FormData.create().set("title", "Book Title").set("body", "John Doe")
351+ * ));
352+ * }</pre>
353+ *
354+ * <p> The common way to send file(s) in the body of a request is to upload them as form fields with {@code multipart/form-data}
355+ * encoding. You can achieve that with Playwright API like this:
356+ * <pre>{@code
357+ * // Pass file path to the form data constructor:
358+ * Path file = Paths.get("team.csv");
359+ * APIResponse response = request.post("https://example.com/api/uploadTeamList",
360+ * RequestOptions.create().setMultipart(
361+ * FormData.create().set("fileField", file)));
362+ *
363+ * // Or you can pass the file content directly as FilePayload object:
364+ * FilePayload filePayload = new FilePayload("f.js", "text/javascript",
365+ * "console.log(2022);".getBytes(StandardCharsets.UTF_8));
366+ * APIResponse response = request.post("https://example.com/api/uploadTeamList",
367+ * RequestOptions.create().setMultipart(
368+ * FormData.create().set("fileField", filePayload)));
369+ * }</pre>
370+ *
191371 * @param url Target URL.
192372 * @param params Optional request parameters.
193373 */
0 commit comments