Send JSON in a POST Request

The planner can now search the trip board with values that arrive intact. The friends have also picked their weekend, May 1 to 3, 2026. It starts with Labor Day, a public holiday in Portugal, Germany, and Mexico. It’s time to post the weekend where all four friends can see it.

In this lesson, you’ll send that weekend to the trip board as a POST request with a JSON body, the request you planned on paper in Choose What a Request Needs. You’ll see what fetch() does with the data you hand it, and you’ll read back the 201 Created that confirms the board stored it. Start by giving fetch() more than a URL.

Give fetch() a Method, Headers, and a Body

Every request so far has been a GET, which is what fetch() sends when you give it only a URL. To send anything else, you pass a second argument, an options object. Its .method property names the method, .headers holds the request headers as name-value pairs, and .body holds the data to send.

You’ll use tripBoard.mjs from Build Query Strings Safely, the stand-in that answers requests to https://trip-board.example/ inside your program. It reads exactly what Node.js’s fetch() sends. If it isn’t in your planner folder yet, then copy it from here:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.