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

Supabase vs. Firebase for AI Coders: Which is Better in 2026?

Supabase vs. Firebase for AI Coders: Which is Better in 2026? As an AI coder, you might find yourself at a crossroads when it comes to backend services. Do you go with the establis

Mar 18, 20263 min read
Ai Coding Tools

GitHub Copilot vs Codeium: Which AI Coding Tool is Worth Your Money?

GitHub Copilot vs Codeium: Which AI Coding Tool is Worth Your Money? As we dive into 2026, the landscape of AI coding tools continues to evolve, and for indie hackers and solo foun

Mar 18, 20263 min read
Ai Coding Tools

How to Write Code in Half the Time with AI Assistants

How to Write Code in Half the Time with AI Assistants (2026) As indie hackers and solo founders, we’re always seeking ways to maximize our productivity. Writing code can be a timec

Mar 18, 20264 min read
Ai Coding Tools

Bolt.new vs Cursor: Which AI Coding Tool Wins in 2026?

Bolt.new vs Cursor: Which AI Coding Tool Wins in 2026? As a solo founder or indie hacker, finding the right AI coding tool can feel like searching for a needle in a haystack. With

Mar 18, 20263 min read
Ai Coding Tools

Bolt.new vs Cursor: Which AI Coding Assistant Saves You More Time?

Bolt.new vs Cursor: Which AI Coding Assistant Saves You More Time? As indie hackers and solo founders, we’re always on the lookout for tools that help us code faster and more effic

Mar 18, 20263 min read
Ai Coding Tools

Best AI Coding Tools for Beginners: 5 Essential Picks for 2026

Best AI Coding Tools for Beginners: 5 Essential Picks for 2026 If you’re a beginner diving into software development, the sheer number of coding tools can be overwhelming. With the

Mar 18, 20264 min read