Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created June 19, 2019 15:25
Show Gist options
  • Select an option

  • Save mattlockyer/3dac7c9618ac98d16b046e32c364899d to your computer and use it in GitHub Desktop.

Select an option

Save mattlockyer/3dac7c9618ac98d16b046e32c364899d to your computer and use it in GitHub Desktop.
Using spread syntax to conditionally add JSON key, value to object. Fetch example using POST and Authorization.
export const POST = (auth) => ({
method: "POST", // *GET, POST, PUT, DELETE, etc.
mode: "cors", // no-cors, cors, *same-origin
headers: {
"Content-Type": "application/json",
...(auth ? { "Authorization": auth } : {})
},
})
@LukasDoesDev

Copy link
Copy Markdown

@abhisekgour

Copy link
Copy Markdown

Thank you, saved my day!

@aclisp

aclisp commented May 18, 2023

Copy link
Copy Markdown

Very helpful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment