Writing Dart/Flutter requests without writing a line

AppVesto LLC
5 min readMar 8, 2021

Good day, my name is Andrew, I am an employee of AppVesto. Today I want to tell you about a small, but very easy-to-use trick, namely, today I will show how to get a ready-made request with prescribed headers and body, using any browser and Postman.

And so for the example I’ll use the Medium site. First, you need to go to the “Inspect element” tab.

Inside we are interested in the “Network” tab. This shows all the requests sent by the site at runtime.

Okay, let’s enter a non-existent email for the example.

Now we look at the network.

We have a new request. Then you need to do the following.

  1. Right-click and select “Copy”
  2. At “Copy” you should choose the item “Copy as cURL (bash)”.
  3. After that all the necessary information is copied to the clipboard
  4. Then we open the postman.

Okay we ended up with something like this:

curl ‘https://medium.com/_/graphql' \-H ‘authority: medium.com’ \-H ‘apollographql-client-name: lite’ \-H ‘medium-frontend-route: ShowAcctSignIn’ \-H ‘ot-tracer-sampled: true’ \-H ‘ot-tracer-traceid: 217ae668698ea647’ \-H ‘medium-frontend-path: /m/signin’ \-H ‘graphql-operation: SendAcctAuthEmail’ \-H ‘content-type: application/json’ \-H ‘accept: */*’ \-H ‘medium-frontend-app: lite/main-20210224–042709–9740f2358f’ \-H ‘user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.396’ \-H ‘apollographql-client-version: main-20210224–042709–9740f2358f’ \-H ‘ot-tracer-spanid: 6d45644d7b9ffcb0’ \-H ‘origin: https://medium.com' \-H ‘sec-fetch-site: same-origin’ \-H ‘sec-fetch-mode: cors’ \-H ‘sec-fetch-dest: empty’ \-H ‘referer: https://medium.com/m/signin' \-H ‘accept-language: en-US,en;q=0.9’ \-H ‘cookie: uid=lo_50b1676ffd8c; sid=1:Wpw9IMaT0hfYLssuUTyUfsQ+vUy+UMrE8AHW+mnNWsdLGx7S57OX2wmqi83OiA5v; optimizelyEndUserId=lo_50b1676ffd8c; _ga=GA1.2.273065020.1604938184; lightstep_guid/lite-web=4d0deddb7f2e444d; lightstep_session_id=339dcdfe6f5b4c49; _parsely_visitor={%22id%22:%22pid=b0b634e9d8628e091f40654ca0862685%22%2C%22session_count%22:6%2C%22last_session_ts%22:1613476823362}; __cfduid=de928934f3680dab70a2c2bc89a2979bd1613755902; __cfruid=df755ce1f89d31c49a4c8638e870bf2741c5854a-1614153532; _gid=GA1.2.1568995504.1614153536; g_state={“i_p”:1614187200289,”i_l”:1}’ \ — data-binary $’{“operationName”:”SendAcctAuthEmail”,”variables”:{“email”:”awejgiwegjiwe@gmail.com”,”operation”:”login”,”redirect”:"https://medium.com/?source=login-------------------------------------","onMobileWeb":false},"query":"mutation SendAcctAuthEmail($email: String\u0021, $redirect: String, $fullName: String, $captchaValue: String, $operation: String, $onMobileWeb: Boolean, $resetPasswordFlow: Boolean) {\\n sendAcctAuthEmail(email: $email, redirect: $redirect, fullName: $fullName, captchaValue: $captchaValue, operation: $operation, onMobileWeb: $onMobileWeb, resetPasswordFlow: $resetPasswordFlow) {\\n … on SusiMethod {\\n value\\n __typename\\n }\\n … on BadRequest {\\n message\\n __typename\\n }\\n … on FailedChallenge {\\n message\\n __typename\\n }\\n … on NotFound {\\n message\\n __typename\\n }\\n __typename\\n }\\n}\\n”}’ \ — compressed

We now need to go to “Postman” and select “Import”.

In the window that comes up, we need to select “Raw text” and paste.

After just click “Continue” and go to the page, here it is not necessary to change anything, you can just click “Import”.

We have a working function, and now we only need to transfer it to Dart. To do this, press the “Code” button.

Here we just need to find the language we need, in our case it is dart, and copy the finished code:

var headers = {‘authority’: ‘medium.com’,‘apollographql-client-name’: ‘lite’,‘medium-frontend-route’: ‘ShowAcctSignIn’,‘ot-tracer-sampled’: ‘true’,‘ot-tracer-traceid’: ‘217ae668698ea647’,‘medium-frontend-path’: ‘/m/signin’,‘graphql-operation’: ‘SendAcctAuthEmail’,‘content-type’: ‘application/json’,‘accept’: ‘*/*’,‘medium-frontend-app’: ‘lite/main-20210224–042709–9740f2358f’,‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.396’,‘apollographql-client-version’: ‘main-20210224–042709–9740f2358f’,‘ot-tracer-spanid’: ‘6d45644d7b9ffcb0’,‘origin’: ‘https://medium.com',‘sec-fetch-site’: ‘same-origin’,‘sec-fetch-mode’: ‘cors’,‘sec-fetch-dest’: ‘empty’,‘referer’: ‘https://medium.com/m/signin',‘accept-language’: ‘en-US,en;q=0.9’,‘cookie’: ‘uid=lo_50b1676ffd8c; sid=1:Wpw9IMaT0hfYLssuUTyUfsQ+vUy+UMrE8AHW+mnNWsdLGx7S57OX2wmqi83OiA5v; optimizelyEndUserId=lo_50b1676ffd8c; _ga=GA1.2.273065020.1604938184; lightstep_guid/lite-web=4d0deddb7f2e444d; lightstep_session_id=339dcdfe6f5b4c49; _parsely_visitor={%22id%22:%22pid=b0b634e9d8628e091f40654ca0862685%22%2C%22session_count%22:6%2C%22last_session_ts%22:1613476823362}; __cfduid=de928934f3680dab70a2c2bc89a2979bd1613755902; __cfruid=df755ce1f89d31c49a4c8638e870bf2741c5854a-1614153532; _gid=GA1.2.1568995504.1614153536; g_state={“i_p”:1614187200289,”i_l”:1}’};var request = http.Request(‘POST’, Uri.parse(‘https://medium.com/_/graphql'));request.body = ‘’’{“operationName”:”SendAcctAuthEmail”,”variables”:{“email”:”awejgiwegjiwe@gmail.com”,”operation”:”login”,”redirect”:”https://medium.com/?source=login-------------------------------------","onMobileWeb":false},"query":"mutation SendAcctAuthEmail(\$email: Stringu0021, \$redirect: String, \$fullName: String, \$captchaValue: String, \$operation: String, \$onMobileWeb: Boolean, \$resetPasswordFlow: Boolean) {\\n sendAcctAuthEmail(email: \$email, redirect: \$redirect, fullName: \$fullName, captchaValue: \$captchaValue, operation: \$operation, onMobileWeb: \$onMobileWeb, resetPasswordFlow: \$resetPasswordFlow) {\\n … on SusiMethod {\\n value\\n __typename\\n }\\n … on BadRequest {\\n message\\n __typename\\n }\\n … on FailedChallenge {\\n message\\n __typename\\n }\\n … on NotFound {\\n message\\n __typename\\n }\\n __typename\\n }\\n}\\n”}’’’;request.headers.addAll(headers);http.StreamedResponse response = await request.send();if (response.statusCode == 200) {print(await response.stream.bytesToString());}else {print(response.reasonPhrase);}

Everything, after that we can safely use, ready request, with all the necessary parameters, headers and body, without writing a single line. Also, this method allows us, with the addition of certain logic, to pass authorization on some sites, which allows us, for example, in some online store, get a list of their favorites.

That’s all for today, leave your feedback, were you useful, this article. Maybe you would also like, about something similar to tell, I’ll be glad to wait for your feedback.

--

--

AppVesto LLC

We are a team of rock-star developers, which provides fully-flexible and powerful products 💥.