[{"data":1,"prerenderedAt":592},["ShallowReactive",2],{"page:\u002Fextensions\u002Fericlm\u002Fkubb-plugin-playwright\u002Fguides\u002Fsend-request-bodies":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":591,"source":4},"extensions\u002Fericlm\u002Fkubb-plugin-playwright\u002Fguides\u002Fsend-request-bodies.md",{},"Send request bodies",{"type":8,"value":9,"toc":582},"minimark",[10,14,19,22,83,86,90,105,527,531,540,553,563,567],[11,12,13],"p",{},"Send JSON, URL-encoded forms, and multipart files through the generated helpers, and know how each body reaches Playwright.",[15,16,18],"h2",{"id":17},"pick-the-body-mode","Pick the body mode",[11,20,21],{},"The first content type declared in the request body decides which native fetch option the helper fills:",[23,24,25,38],"table",{},[26,27,28],"thead",{},[29,30,31,35],"tr",{},[32,33,34],"th",{},"Content type",[32,36,37],{},"Fetch option",[39,40,41,59,71],"tbody",{},[29,42,43,54],{},[44,45,46,50,51],"td",{},[47,48,49],"code",{},"application\u002Fjson"," or a media type ending in ",[47,52,53],{},"+json",[44,55,56],{},[47,57,58],{},"data",[29,60,61,66],{},[44,62,63],{},[47,64,65],{},"application\u002Fx-www-form-urlencoded",[44,67,68],{},[47,69,70],{},"form",[29,72,73,78],{},[44,74,75],{},[47,76,77],{},"multipart\u002Fform-data",[44,79,80],{},[47,81,82],{},"multipart",[11,84,85],{},"Operations whose first content type is not in this table are skipped.",[15,87,89],{"id":88},"send-each-kind-of-body","Send each kind of body",[11,91,92,93,96,97,100,101,104],{},"Pass the typed body as ",[47,94,95],{},"body",". Form arrays become repeated fields, and multipart ",[47,98,99],{},"Blob"," values become file fields through ",[47,102,103],{},"FormData",".",[106,107,112],"pre",{"language":108,"filename":109,"code":110,"class":111},"typescript","bodies.spec.ts","import { expect, test } from '@playwright\u002Ftest'\nimport { pwAddPet, pwUpdatePetDetails, pwUploadPetPhoto } from '.\u002Fsrc\u002Fgen\u002Fplaywright'\n\ntest.use({ baseURL: 'http:\u002F\u002F127.0.0.1:3000' })\n\ntest('sends JSON, form fields and a file', async ({ request }) => {\n  const response = await pwAddPet({ request, body: { name: 'Rex' } })\n  const pet = await response.json()\n  expect(pet.name).toBe('Rex')\n\n  await pwUpdatePetDetails({\n    request,\n    path: { petId: '123' },\n    body: { name: 'Rex', tags: ['friendly', 'small'] },\n  })\n\n  await pwUploadPetPhoto({\n    request,\n    path: { petId: '123' },\n    body: { file: new Blob(['file contents']), description: 'Rex', tags: ['profile'] },\n  })\n})","highlights",[47,113,115,148,149,148,175,148,177,148,203,148,205,148,234,148,277,148,301,148,331,148,333,148,344,148,354,148,378,148,417,148,423,148,425,148,436,148,444,148,464,148,517,148,523],{"class":114},"language-typescript",[116,117,120,124,128,132,135,138,141,144],"span",{"class":118,"style":119},"line","display: inline",[116,121,123],{"style":122},"color:#d73a49;--hls-dark:#f97583","import ",[116,125,127],{"style":126},"color:#005cc5;--hls-dark:#79b8ff","{ ",[116,129,131],{"style":130},"color:#24292e;--hls-dark:#e1e4e8","expect",[116,133,134],{"style":122},", ",[116,136,137],{"style":130},"test ",[116,139,140],{"style":126},"} ",[116,142,143],{"style":122},"from ",[116,145,147],{"style":146},"color:#032f62;--hls-dark:#9ecbff","'@playwright\u002Ftest'","\n",[116,150,151,153,155,158,160,163,165,168,170,172],{"class":118,"style":119},[116,152,123],{"style":122},[116,154,127],{"style":126},[116,156,157],{"style":130},"pwAddPet",[116,159,134],{"style":122},[116,161,162],{"style":130},"pwUpdatePetDetails",[116,164,134],{"style":122},[116,166,167],{"style":130},"pwUploadPetPhoto ",[116,169,140],{"style":126},[116,171,143],{"style":122},[116,173,174],{"style":146},"'.\u002Fsrc\u002Fgen\u002Fplaywright'",[116,176],{"class":118,"style":119},[116,178,179,182,184,188,191,194,197,200],{"class":118,"style":119},[116,180,181],{"style":130},"test",[116,183,104],{"style":122},[116,185,187],{"style":186},"color:#6f42c1;--hls-dark:#b392f0","use",[116,189,190],{"style":126},"({ ",[116,192,193],{"style":126},"baseURL",[116,195,196],{"style":122},": ",[116,198,199],{"style":146},"'http:\u002F\u002F127.0.0.1:3000' ",[116,201,202],{"style":126},"})",[116,204],{"class":118,"style":119},[116,206,207,209,212,215,217,220,222,225,228,231],{"class":118,"style":119},[116,208,181],{"style":186},[116,210,211],{"style":126},"(",[116,213,214],{"style":146},"'sends JSON, form fields and a file'",[116,216,134],{"style":122},[116,218,219],{"style":122},"async ",[116,221,190],{"style":126},[116,223,224],{"style":130},"request ",[116,226,227],{"style":126},"}) ",[116,229,230],{"style":122},"=> ",[116,232,233],{"style":126},"{",[116,235,236,239,242,245,248,251,253,255,258,260,262,264,266,269,271,274],{"class":118,"style":119},[116,237,238],{"style":126},"  ",[116,240,241],{"style":122},"const ",[116,243,244],{"style":130},"response ",[116,246,247],{"style":122},"= ",[116,249,250],{"style":122},"await ",[116,252,157],{"style":186},[116,254,190],{"style":126},[116,256,257],{"style":130},"request",[116,259,134],{"style":122},[116,261,95],{"style":126},[116,263,196],{"style":122},[116,265,127],{"style":126},[116,267,268],{"style":126},"name",[116,270,196],{"style":122},[116,272,273],{"style":146},"'Rex' ",[116,275,276],{"style":126},"} })",[116,278,279,281,283,286,288,290,293,295,298],{"class":118,"style":119},[116,280,238],{"style":126},[116,282,241],{"style":122},[116,284,285],{"style":130},"pet ",[116,287,247],{"style":122},[116,289,250],{"style":122},[116,291,292],{"style":130},"response",[116,294,104],{"style":122},[116,296,297],{"style":186},"json",[116,299,300],{"style":126},"()",[116,302,303,305,307,309,312,314,316,319,321,324,326,329],{"class":118,"style":119},[116,304,238],{"style":126},[116,306,131],{"style":186},[116,308,211],{"style":126},[116,310,311],{"style":130},"pet",[116,313,104],{"style":122},[116,315,268],{"style":126},[116,317,318],{"style":126},")",[116,320,104],{"style":122},[116,322,323],{"style":186},"toBe",[116,325,211],{"style":126},[116,327,328],{"style":146},"'Rex'",[116,330,318],{"style":126},[116,332],{"class":118,"style":119},[116,334,335,337,339,341],{"class":118,"style":119},[116,336,238],{"style":126},[116,338,250],{"style":122},[116,340,162],{"style":186},[116,342,343],{"style":126},"({",[116,345,346,349,351],{"class":118,"style":119},[116,347,348],{"style":126},"    ",[116,350,257],{"style":130},[116,352,353],{"style":122},",",[116,355,356,358,361,363,365,368,370,373,376],{"class":118,"style":119},[116,357,348],{"style":122},[116,359,360],{"style":126},"path",[116,362,196],{"style":122},[116,364,127],{"style":126},[116,366,367],{"style":126},"petId",[116,369,196],{"style":122},[116,371,372],{"style":146},"'123' ",[116,374,375],{"style":126},"}",[116,377,353],{"style":122},[116,379,380,382,384,386,388,390,392,394,396,399,401,404,407,409,412,415],{"class":118,"style":119},[116,381,348],{"style":122},[116,383,95],{"style":126},[116,385,196],{"style":122},[116,387,127],{"style":126},[116,389,268],{"style":126},[116,391,196],{"style":122},[116,393,328],{"style":146},[116,395,134],{"style":122},[116,397,398],{"style":126},"tags",[116,400,196],{"style":122},[116,402,403],{"style":126},"[",[116,405,406],{"style":146},"'friendly'",[116,408,134],{"style":122},[116,410,411],{"style":146},"'small'",[116,413,414],{"style":126},"] }",[116,416,353],{"style":122},[116,418,419,421],{"class":118,"style":119},[116,420,238],{"style":122},[116,422,202],{"style":126},[116,424],{"class":118,"style":119},[116,426,427,429,431,434],{"class":118,"style":119},[116,428,238],{"style":126},[116,430,250],{"style":122},[116,432,433],{"style":186},"pwUploadPetPhoto",[116,435,343],{"style":126},[116,437,438,440,442],{"class":118,"style":119},[116,439,348],{"style":126},[116,441,257],{"style":130},[116,443,353],{"style":122},[116,445,446,448,450,452,454,456,458,460,462],{"class":118,"style":119},[116,447,348],{"style":122},[116,449,360],{"style":126},[116,451,196],{"style":122},[116,453,127],{"style":126},[116,455,367],{"style":126},[116,457,196],{"style":122},[116,459,372],{"style":146},[116,461,375],{"style":126},[116,463,353],{"style":122},[116,465,466,468,470,472,474,477,479,482,484,487,490,493,495,498,500,502,504,506,508,510,513,515],{"class":118,"style":119},[116,467,348],{"style":122},[116,469,95],{"style":126},[116,471,196],{"style":122},[116,473,127],{"style":126},[116,475,476],{"style":126},"file",[116,478,196],{"style":122},[116,480,481],{"style":122},"new ",[116,483,99],{"style":186},[116,485,486],{"style":126},"([",[116,488,489],{"style":146},"'file contents'",[116,491,492],{"style":126},"])",[116,494,134],{"style":122},[116,496,497],{"style":126},"description",[116,499,196],{"style":122},[116,501,328],{"style":146},[116,503,134],{"style":122},[116,505,398],{"style":126},[116,507,196],{"style":122},[116,509,403],{"style":126},[116,511,512],{"style":146},"'profile'",[116,514,414],{"style":126},[116,516,353],{"style":122},[116,518,519,521],{"class":118,"style":119},[116,520,238],{"style":122},[116,522,202],{"style":126},[116,524,525],{"class":118,"style":119},[116,526,202],{"style":126},[15,528,530],{"id":529},"serialization","Serialization",[11,532,533,534,536,537,539],{},"Playwright serializes the body and sets the Content-Type. JSON helpers pass ",[47,535,95],{}," as ",[47,538,58],{},", so objects use Playwright's JSON serialization and primitive values follow its native behavior.",[11,541,542,543,545,546,548,549,552],{},"A ",[47,544,53],{}," media type selects ",[47,547,58],{}," but does not set that Content-Type. Set ",[47,550,551],{},"options.headers"," when the API needs the exact media type.",[11,554,555,556,559,560,104],{},"Values that Playwright accepts natively pass through unchanged. When the helper has to convert form or query values, it leaves out ",[47,557,558],{},"null"," and ",[47,561,562],{},"undefined",[15,564,566],{"id":565},"replace-or-switch-the-body","Replace or switch the body",[11,568,569,570,573,574,577,578,581],{},"To send a different body, set the same native option in ",[47,571,572],{},"options",", for example ",[47,575,576],{},"options: { data: rawJson }",". To switch modes, also clear the generated one, for example ",[47,579,580],{},"options: { data: undefined, form: { name: 'Rex' } }"," on a JSON helper. Otherwise Playwright receives two body modes and rejects the request.",{"title":583,"searchDepth":584,"depth":584,"links":585},"",5,[586,588,589,590],{"id":17,"depth":587,"text":18},2,{"id":88,"depth":587,"text":89},{"id":529,"depth":587,"text":530},{"id":565,"depth":587,"text":566},"\u002Fextensions\u002Fericlm\u002Fkubb-plugin-playwright\u002Fguides\u002Fsend-request-bodies",1793488215145]