Ai Coding Tools

How to Build a Simple API with GitHub Copilot in Under 2 Hours

By BTW Team3 min read

How to Build a Simple API with GitHub Copilot in Under 2 Hours

If you're like many indie hackers, you might find yourself needing an API for your project but feeling overwhelmed by the complexity of building one from scratch. The good news? With GitHub Copilot, you can whip up a simple API in under 2 hours. I know—I've done it myself and can vouch for how effective it is when you know what you're doing.

Prerequisites

Before diving in, make sure you have the following:

  • GitHub Account: You need access to GitHub to use Copilot.
  • Visual Studio Code: This is where you'll be writing your code.
  • Node.js: Ensure you have Node installed (preferably version 14 or higher).
  • Basic JavaScript Knowledge: Familiarity with JavaScript will help you understand the generated code.

Step-by-Step Guide to Building Your API

Step 1: Set Up Your Environment

  1. Install Node.js: You can download it from nodejs.org.
  2. Create a New Directory: Open your terminal and run:
    mkdir my-simple-api
    cd my-simple-api
    
  3. Initialize a New Node Project: Run:
    npm init -y
    

Step 2: Install Dependencies

You'll need express, a popular Node.js framework for building APIs.

npm install express

Step 3: Enable GitHub Copilot

  1. Install the GitHub Copilot Extension: Go to the Extensions Marketplace in Visual Studio Code and search for "GitHub Copilot".
  2. Sign in: Follow the prompts to authenticate your GitHub account.

Step 4: Start Coding

  1. Create a New File: Create a file named app.js.
  2. Write the API Code: Start typing a comment like // create an express app. GitHub Copilot will suggest the code for you. Here’s how it might look:
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;

app.get('/api/hello', (req, res) => {
    res.json({ message: 'Hello, World!' });
});

app.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}`);
});
  1. Run Your API: In the terminal, run:
    node app.js
    

Step 5: Test Your API

Open your browser and navigate to http://localhost:3000/api/hello. You should see:

{"message":"Hello, World!"}

Troubleshooting Common Issues

  • Port Already in Use: If you see an error about the port being in use, try changing the PORT variable to another number.
  • Copilot Not Suggesting Code: Make sure you are logged in and your internet connection is stable.

What's Next?

Now that you have a simple API running, consider adding more endpoints, connecting to a database, or deploying it to a service like Heroku or Vercel.

Tool Comparison: GitHub Copilot vs. Other AI Coding Tools

| Tool | Pricing | Best For | Limitations | Our Verdict | |---------------------|-------------------------|-------------------------|-----------------------------------|---------------------------------| | GitHub Copilot | $10/mo, $100/yr | Rapid coding assistance | Limited to suggestions; not perfect| We use this for quick prototyping | | Tabnine | Free + $12/mo pro | Autocompletion | Less context-aware than Copilot | We don't use this because it's less intuitive | | Codeium | Free | General code assistance | Limited integrations | We don't use this; lacks features | | Sourcery | Free + $20/mo for pro | Refactoring code | Focused more on Python | We don't use this; not versatile enough | | Replit | Free + $7/mo for pro | Collaborative coding | Limited to their environment | We use this for quick demos | | Kite | Free + $19.90/mo | Python coding | Limited to Python only | We don't use this; niche focus |

Conclusion

Building a simple API with GitHub Copilot is not only feasible but can also be a fun learning experience. In just about 2 hours, you can have a functional API up and running. If you're looking for a quick solution to get your project off the ground, start here with GitHub Copilot.

Follow Our Building Journey

Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.

Subscribe

Never miss an episode

Subscribe to Built This Week for weekly insights on AI tools, product building, and startup lessons from Ryz Labs.

Subscribe
Ai Coding Tools

How to Integrate GitHub Copilot into Your Existing Workflow in Under 30 Minutes

How to Integrate GitHub Copilot into Your Existing Workflow in Under 30 Minutes If you're a solo founder or indie hacker, time is your most precious resource. Integrating GitHub Co

May 4, 20263 min read
Ai Coding Tools

AI Coding Tools Showdown: Cursor vs Codeium - Which is Right for You?

AI Coding Tools Showdown: Cursor vs Codeium Which is Right for You? As a solo founder or indie hacker, choosing the right AI coding tool can feel like navigating a maze. With so m

May 4, 20263 min read
Ai Coding Tools

7 Mistakes Developers Make When Using AI Coding Tools

7 Mistakes Developers Make When Using AI Coding Tools In 2026, AI coding tools have become a staple in the developer's toolkit, promising to streamline workflows and automate munda

May 4, 20265 min read
Ai Coding Tools

How to Integrate GitHub Copilot in 60 Minutes for Your Next Project

How to Integrate GitHub Copilot in 60 Minutes for Your Next Project If you're a solo founder or indie hacker, you know that time is money. Every minute spent coding is a minute not

May 4, 20263 min read
Ai Coding Tools

AI Coders Showdown: Cursor vs GitHub Copilot

AI Coders Showdown: Cursor vs GitHub Copilot (2026) As we dive deeper into 2026, the landscape of AI coding assistants has become increasingly crowded, with Cursor and GitHub Copil

May 4, 20263 min read
Ai Coding Tools

How to Build Your First Chatbot with AI Tools in Under 2 Hours

How to Build Your First Chatbot with AI Tools in Under 2 Hours Building a chatbot can feel like a daunting task for beginners, especially when you hear about the complexities of AI

May 4, 20264 min read