<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Borja Canseco</title>
    <description>The latest articles on Forem by Borja Canseco (@bcanseco).</description>
    <link>https://forem.com/bcanseco</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F218368%2Ffed6a9b7-40ae-4c39-942d-273203027a3e.jpg</url>
      <title>Forem: Borja Canseco</title>
      <link>https://forem.com/bcanseco</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bcanseco"/>
    <language>en</language>
    <item>
      <title>Autofill your GitHub contribution graph</title>
      <dc:creator>Borja Canseco</dc:creator>
      <pubDate>Wed, 03 Jun 2020 14:46:13 +0000</pubDate>
      <link>https://forem.com/bcanseco/autofill-your-github-contribution-graph-3j6l</link>
      <guid>https://forem.com/bcanseco/autofill-your-github-contribution-graph-3j6l</guid>
      <description>&lt;p&gt;I made a &lt;a href="https://github.com/marketplace/actions/autopopulate-your-contribution-graph"&gt;GitHub Action&lt;/a&gt; that lets you automatically fill up your GitHub contribution graph without even needing to leave your browser.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maybe most of your coding happens on another version control host, like GitLab or Bitbucket.&lt;/li&gt;
&lt;li&gt;Maybe your company uses GitHub Enterprise but hasn't enabled &lt;a href="https://help.github.com/en/enterprise/2.20/admin/installation/enabling-unified-contributions-between-github-enterprise-server-and-githubcom"&gt;unified contributions&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Maybe you're looking for a new software development job and are worried that recruiters will prejudge you by your scarce contribution graph.&lt;/li&gt;
&lt;li&gt;Or maybe you have &lt;a href="https://twitter.com/jacobmparis/status/1265740598277025792"&gt;other reasons&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whatever the case may be, this Action will get the job done. 🙈 You can set up recurring commits and/or backfill commits from the week, month, year, and more. Want to skip weekends? No problem.&lt;/p&gt;

&lt;p&gt;It's a super simple Docker action powered by Node. You can check out the source code below!&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/bcanseco"&gt;
        bcanseco
      &lt;/a&gt; / &lt;a href="https://github.com/bcanseco/github-contribution-graph-action"&gt;
        github-contribution-graph-action
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      🙈 This GitHub action will automatically push empty commits to one of your repositories.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;
  &lt;a rel="noopener noreferrer" href="https://github.com/bcanseco/github-contribution-graph-action./.github/images/cover.png"&gt;&lt;img width="150px" src="https://res.cloudinary.com/practicaldev/image/fetch/s--v3_xPC2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bcanseco/github-contribution-graph-action./.github/images/cover.png"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;h1&gt;
  Contribution Graph Action
&lt;/h1&gt;

&lt;p&gt;
  &lt;a href="https://github.com/bcanseco/github-contribution-graph-action/actions?query=workflow%3Abuild"&gt;
    &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3IIUBJeD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bcanseco/github-contribution-graph-action/workflows/build/badge.svg"&gt;
  &lt;/a&gt;
  &lt;a href="https://github.com/bcanseco/github-contribution-graph-action/actions?query=workflow%3Atests"&gt;
    &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v1w-948Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bcanseco/github-contribution-graph-action/workflows/tests/badge.svg"&gt;
  &lt;/a&gt;
  &lt;a href="https://github.com/bcanseco/github-contribution-graph-action/actions?query=workflow%3Aaudit"&gt;
    &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1duYL5c7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bcanseco/github-contribution-graph-action/workflows/audit/badge.svg"&gt;
  &lt;/a&gt;
  &lt;a href="https://github.com/marketplace/actions/autopopulate-your-contribution-graph"&gt;
    &lt;img src="https://camo.githubusercontent.com/94bb42b6cd1d8251d6d4e1f4662b1a0adce004369e5a76d085dac58d4f4f1a3b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616374696f6e2d6d61726b6574706c6163652d6f72616e67653f6c6f676f3d676974687562"&gt;
  &lt;/a&gt;
  &lt;a href="https://github.com/bcanseco/github-contribution-graph-action/releases"&gt;
    &lt;img src="https://camo.githubusercontent.com/61be4cc8c62cdb9cb357d1c11b1d9eef0fb9b97c2af211a8e1aec4930dd9ecef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6263616e7365636f2f6769746875622d636f6e747269627574696f6e2d67726170682d616374696f6e2e7376673f6c6f676f3d676974687562"&gt;
  &lt;/a&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Maybe most of your coding happens on another version control host, like GitLab or Bitbucket. Maybe your company uses GitHub Enterprise but hasn't enabled &lt;a href="https://docs.github.com/en/enterprise-server@latest/admin/configuration/configuring-github-connect/enabling-unified-contributions-for-your-enterprise"&gt;unified contributions&lt;/a&gt;. Maybe you're looking for a new software development job and are worried that recruiters will prejudge you by your scarce contribution graph.&lt;br&gt;
Or maybe you have &lt;a href="https://twitter.com/jacobmparis/status/1265740598277025792" rel="nofollow"&gt;other reasons&lt;/a&gt;. Whatever the case may be, you've come to the right place.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
Quick start without leaving your browser ⚡
&lt;/h2&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/new"&gt;Create a new repo&lt;/a&gt; (preferably private unless you have no shame)&lt;/li&gt;
&lt;li&gt;Click on &lt;strong&gt;Create a new file&lt;/strong&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/bcanseco/github-contribution-graph-action./.github/images/create-new-file.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZW2JuMhs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bcanseco/github-contribution-graph-action./.github/images/create-new-file.png" alt=""&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Name your file...&lt;/strong&gt; field, type in &lt;code&gt;.github/workflows/main.yml&lt;/code&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/bcanseco/github-contribution-graph-action./.github/images/name-new-file.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eX7iIJuo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/bcanseco/github-contribution-graph-action./.github/images/name-new-file.png" alt=""&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Paste in one of the YAML file contents below, depending on what you want to do. Be sure to update &lt;code&gt;GIT_EMAIL&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;Commit new file&lt;/strong&gt; button at the bottom of the page. You're all set

&lt;ul&gt;
&lt;li&gt;Note that you must enable the option below in your…&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/bcanseco/github-contribution-graph-action"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>showdev</category>
      <category>githunt</category>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>Request body encoding: JSON? x-www-form-urlencoded?</title>
      <dc:creator>Borja Canseco</dc:creator>
      <pubDate>Sat, 28 Sep 2019 02:40:07 +0000</pubDate>
      <link>https://forem.com/bcanseco/request-body-encoding-json-x-www-form-urlencoded-ad9</link>
      <guid>https://forem.com/bcanseco/request-body-encoding-json-x-www-form-urlencoded-ad9</guid>
      <description>&lt;p&gt;I'm planning a new API and was curious about what kind of requests I should accept.&lt;/p&gt;

&lt;p&gt;The most common &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type" rel="noopener noreferrer"&gt;Content-Types&lt;/a&gt; I've seen for popular modern REST APIs include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;application/json&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Shout-out to &lt;code&gt;application/graphql&lt;/code&gt; too, but this article will focus on the two above :)&lt;/p&gt;

&lt;p&gt;Of course, when just starting out it's easy to accept both and forget about it. For example...&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;bodyParser&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;body-parser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// application/x-www-form-urlencoded&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlencoded&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;extended&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;}));&lt;/span&gt;

&lt;span class="c1"&gt;// application/json&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
A minimal example of a Node.js webserver accepting both request body types


&lt;p&gt;I've done this many times in the past. However, I wanted to set out and discover the true pros and cons of each. I wanted to understand &lt;em&gt;why&lt;/em&gt; someone would choose one over the other.&lt;/p&gt;
&lt;h1&gt;
  
  
  Initial bias
&lt;/h1&gt;

&lt;p&gt;Before I started my search, I wanted to keep my biases in check. What do I currently believe and what am I probably predisposed to want to validate?&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;application/json&lt;/code&gt; is beginner-friendly...mostly
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/axios" rel="noopener noreferrer"&gt;&lt;code&gt;axios&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/superagent" rel="noopener noreferrer"&gt;&lt;code&gt;superagent&lt;/code&gt;&lt;/a&gt;, two of the more popular npm HTTP libraries, work with JSON bodies by default. To send as &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt;, you have to add additional configuration options.&lt;/p&gt;

&lt;p&gt;For example, here's how you might do it with axios. Leveraging a querystring encoding library is necessary:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;qs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;qs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/resource&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;qs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;It's not really a significant amount of boilerplate, but it's something I've run into in the past.&lt;/p&gt;

&lt;p&gt;On the other hand, tools like &lt;a href="https://www.getpostman.com/" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; are much easier to work with when using &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffqp0v7i4igiu7j80iztv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffqp0v7i4igiu7j80iztv.gif" alt="Postman urlencoded demo"&gt;&lt;/a&gt;&lt;/p&gt;
Toggling and descriptions? Fantastic!



&lt;p&gt;Whereas &lt;code&gt;application/json&lt;/code&gt; doesn't allow toggling nor describing individual keys:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzlqat0suweogytl2z9ij.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzlqat0suweogytl2z9ij.gif" alt="Postman json demo"&gt;&lt;/a&gt;&lt;/p&gt;
Yeah yeah, I know. Comments aren't valid JSON anyway. But come on!


&lt;h3&gt;
  
  
  URL encoding is used by some of the best APIs out there
&lt;/h3&gt;

&lt;p&gt;I commonly see Stripe referred to as &lt;a href="https://www.google.com/search?q=%22gold+standard%22+stripe+api" rel="noopener noreferrer"&gt;the gold standard&lt;/a&gt; as far as API quality. Guess what encoding they use?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Stripe API is organized around REST. Our API has predictable resource-oriented URLs, &lt;strong&gt;accepts form-encoded request bodies&lt;/strong&gt;, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs&lt;/p&gt;

&lt;p&gt;-- &lt;a href="https://stripe.com/docs/api" rel="noopener noreferrer"&gt;Stripe Docs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And it's not just them. Twilio, the market leader for SMS, is on the same page:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Creating or updating a resource involves performing an HTTP PUT or HTTP POST to a resource URI. In the PUT or POST, you represent the properties of the object you wish to update as form urlencoded key/value pairs. Don't worry, this is already the way browsers encode POSTs by default. &lt;strong&gt;But be sure to set the HTTP Content-Type header to "application/x-www-form-urlencoded" for your requests if you are writing your own client.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;-- &lt;a href="https://www.twilio.com/docs/usage/your-request-to-twilio#post" rel="noopener noreferrer"&gt;Twilio Docs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These folks have got to know what they're doing, right?&lt;/p&gt;



&lt;p&gt;Okay, so some positive and negative biases in regards to both approaches. At this point, I started Googling around. My main search terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;application/json vs application/x-www-form-urlencoded&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;json vs form&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;differences&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;performance&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;best practices&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  What I learned
&lt;/h1&gt;
&lt;h3&gt;
  
  
  Preflight OPTIONS requests are always sent with JSON
&lt;/h3&gt;

&lt;p&gt;Essentially, there's &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests" rel="noopener noreferrer"&gt;a whitelist&lt;/a&gt; of request properties and values. As long as your HTTP requests stay within this whitelist, no preflight requests are sent.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;application/json&lt;/code&gt; Content-Type isn't on the list, so using this for requests will result in preflight requests. You can read more about this below:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;The whitelist is fairly restrictive. No &lt;code&gt;Authorization&lt;/code&gt; headers, &lt;code&gt;Cache-Control&lt;/code&gt;, &lt;code&gt;Keep-Alive&lt;/code&gt;, etc. I'd recommend not trying to circumvent CORS in this regard unless you find there's a significant performance opportunity and minimal additional code complexity.&lt;/p&gt;

&lt;h3&gt;
  
  
  URL encoded arrays can be a nightmare
&lt;/h3&gt;

&lt;p&gt;Sending any kind of complex data with &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt; has historically been...not ideal.&lt;/p&gt;

&lt;p&gt;The following are two patterns I've seen for sending an array called &lt;code&gt;a&lt;/code&gt; with members &lt;code&gt;b&lt;/code&gt; and &lt;code&gt;c&lt;/code&gt;. Neither of them are particularly great:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;a[]=b&amp;amp;a[]=c&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;a[0]=b&amp;amp;a[1]=c&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For larger payloads, you may be &lt;a href="https://stackoverflow.com/a/26527335/6609109" rel="noopener noreferrer"&gt;saving bytes with JSON&lt;/a&gt; as well.&lt;/p&gt;

&lt;h1&gt;
  
  
  tl;dr
&lt;/h1&gt;

&lt;p&gt;If you can do so securely, support both content types. Always sanitize user input, don't bite off more than you can chew, etc.&lt;/p&gt;

&lt;p&gt;If you must choose &lt;em&gt;one&lt;/em&gt; request body for your API, go with whatever works for your use case.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For complex data (especially array/nested object parameters) or if you already return JSON and want to be consistent: consider &lt;code&gt;application/json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For mostly flat param trees, &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt; is tried and tested. After all, it's the default for browsers! &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Further reading
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://m.alphasights.com/killing-cors-preflight-requests-on-a-react-spa-1f9b04aa5730" rel="noopener noreferrer"&gt;https://m.alphasights.com/killing-cors-preflight-requests-on-a-react-spa-1f9b04aa5730&lt;/a&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
