Writing Your First RESTful API

The hello world of APIs

Last updated: 2/28/2025

1 hour
Medium

Writing Your First RESTful API - "Hello World"

🌐 Introduction

Welcome to your first RESTful API project! In this lesson, you’ll create a basic API with a single GET endpoint (/hello) that responds with "Hello World" and a 200 OK status.

This project introduces you to:

  • Setting up a basic server.
  • Defining routes and handling requests.
  • Sending HTTP responses.

πŸš€ Project Requirements

Your API should: βœ… Have a GET endpoint at /hello.
βœ… Respond with a 200 OK status.
βœ… Return the text "Hello World".
βœ… Run on port 3033.

You can use any backend framework or language (Node.js, Python, Java, etc.).


πŸ›  Setting Up Your API (Node.js + Express Example)

We’ll use Node.js and Express, but you can use any backend framework of your choice.

Step 1: Create a New Project

Open a terminal and run:

mkdir hello-world-api cd hello-world-api npm init -y

Step 2: Install Express.js

npm install express

Step 3: Create index.js

Now, create a new file called index.js and add this code:

const express = require('express'); const app = express(); // Define the /hello route app.get('/hello', (req, res) => { res.status(200).send('Hello World'); }); // Start the server on port 3033 const PORT = 3033; app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); });

πŸƒ Running Your Server

Start the API by running:

node index.js

If successful, you should see:

Server running on http://localhost:3033

πŸ” Testing Your API

βœ… 1️⃣ Using a Web Browser

Open http://localhost:3033/hello in your browser.
You should see:

Hello World

βœ… 2️⃣ Using cURL (Command Line)

Run:

curl -X GET http://localhost:3033/hello

Expected output:

Hello World

βœ… 3️⃣ Using Postman

  1. Open Postman.
  2. Create a GET request to http://localhost:3033/hello.
  3. Click Send.
  4. You should see "Hello World" in the response.

πŸ“‚ Pushing Your Project to GitHub

To submit your project for evaluation, you need to upload it to GitHub.

Step 1: Create a GitHub Repository

  1. Go to GitHub.
  2. Click New Repository.
  3. Name it hello-world-api.
  4. Select Public or Private (based on your preference).
  5. Click Create Repository.

Step 2: Initialize Git Locally

Run the following commands in your project directory:

git init git add . git commit -m "Initial commit - Hello World API"

Step 3: Link Your GitHub Repository

Replace <your-github-username> with your actual username:

git remote add origin https://github.com/<your-github-username>/hello-world-api.git git branch -M main git push -u origin main

Step 4: Verify the Push

Go to your GitHub repository and confirm that the files are uploaded.


🎯 Summary

  • We created a basic REST API using Express.js.
  • The API has a GET route at /hello that returns "Hello World" with a 200 OK response.
  • The server runs on port 3033.
  • We tested the API using a browser, cURL, and Postman.
  • We uploaded the project to GitHub for submission.

βœ… Next Lesson: Submitting Your Project for Evaluation

In the next lesson, which is the very first project in this learning track, you will submit the project you just implemented right now to be evaluated and receive the verdict.