<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ritik Kumar</title>
    <description>The latest articles on DEV Community by Ritik Kumar (@ritik_kumar_9883dbfcef054).</description>
    <link>https://dev.to/ritik_kumar_9883dbfcef054</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3560240%2Feb459c17-2ce3-40cd-9750-13da71ac6c7e.png</url>
      <title>DEV Community: Ritik Kumar</title>
      <link>https://dev.to/ritik_kumar_9883dbfcef054</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ritik_kumar_9883dbfcef054"/>
    <language>en</language>
    <item>
      <title>Become a 1% Developer: Create a REST API Without Any Framework (No Spring Boot, No Spring!)</title>
      <dc:creator>Ritik Kumar</dc:creator>
      <pubDate>Sun, 12 Oct 2025 09:41:05 +0000</pubDate>
      <link>https://dev.to/ritik_kumar_9883dbfcef054/become-a-1-developer-create-a-rest-api-without-any-framework-no-spring-boot-no-spring-445g</link>
      <guid>https://dev.to/ritik_kumar_9883dbfcef054/become-a-1-developer-create-a-rest-api-without-any-framework-no-spring-boot-no-spring-445g</guid>
      <description>&lt;p&gt;If you’ve landed on this page, it probably means you’re one of those rare developers who want to dig deeper — someone who wants to understand how things really work under the hood.&lt;/p&gt;

&lt;p&gt;I was exactly like you — curious, restless, and eager to learn how web servers actually handle requests without relying on frameworks like Spring Boot or Spring.&lt;/p&gt;

&lt;p&gt;So, in this article, I’ll walk you through how to build a REST API endpoint from scratch in Java — no frameworks, no magic, just the raw fundamentals.&lt;/p&gt;

&lt;p&gt;🧩 Step 1: Create a New Maven Project&lt;/p&gt;

&lt;p&gt;Start by creating a simple Maven project. You don’t need any extra dependencies for this tutorial — Java’s built-in libraries are more than enough.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2b81jhsn8c02puvf5qnf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2b81jhsn8c02puvf5qnf.png" alt=" " width="800" height="618"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🧠 Step 2: The Minimal Code to Get Started&lt;/p&gt;

&lt;p&gt;Here’s all the code you need to spin up a basic REST API server using pure Java:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.ritik;

import com.sun.net.httpserver.HttpServer;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class Main {
    static void main() {
        try {
            HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);

            // First Endpoint
            server.createContext("/api/hello", (exchange) -&amp;gt; {
                System.out.println("Request Came");
                String response = "Hello World!";
                exchange.sendResponseHeaders(200, response.getBytes().length);
                OutputStream outputStream = exchange.getResponseBody();
                outputStream.write(response.getBytes());
                outputStream.flush();
                exchange.close();
            });

            // Second Endpoint
            server.createContext("/api/world", (exchange) -&amp;gt; {
                if (exchange.getRequestMethod().equalsIgnoreCase("GET")) {
                    System.out.println("Request Came");
                    String response = "Thanks for connecting with the world!";
                    exchange.sendResponseHeaders(200, response.getBytes().length);
                    OutputStream outputStream = exchange.getResponseBody();
                    outputStream.write(response.getBytes());
                    outputStream.flush();
                } else {
                    exchange.sendResponseHeaders(404, -1);
                }
                exchange.close();
            });

            server.start();
            System.out.println("Server started on port 8080");

        } catch (Exception e) {
            System.out.println("Error Creating Server: " + e.getLocalizedMessage());
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚙️ Step 3: Breaking Down the Code&lt;/p&gt;

&lt;p&gt;Let’s unpack what’s happening here.&lt;/p&gt;

&lt;p&gt;🔹 HttpServer&lt;/p&gt;

&lt;p&gt;This is the heart of our setup.&lt;br&gt;
HttpServer is a built-in Java class that helps us create lightweight HTTP servers without needing any external dependencies.&lt;/p&gt;

&lt;p&gt;You can think of it as a minimal version of what frameworks like Spring Boot do behind the scenes.&lt;/p&gt;

&lt;p&gt;We create an instance using:&lt;br&gt;
&lt;code&gt;HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;🔹 server.createContext()&lt;/p&gt;

&lt;p&gt;This is where the magic happens.&lt;/p&gt;

&lt;p&gt;The createContext() method acts like a router. It maps a URL path (like /api/hello) to the logic that should run when that path is accessed.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;server.createContext("/api/hello", (exchange) -&amp;gt; { ... });&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inside this block, you handle everything from request validation to response writing.&lt;/p&gt;

&lt;p&gt;🔹 Sending Responses&lt;/p&gt;

&lt;p&gt;Every time your API endpoint is called, you need to send back a response.&lt;br&gt;
You do this with two main steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exchange.sendResponseHeaders(200, response.getBytes().length);
OutputStream outputStream = exchange.getResponseBody();
outputStream.write(response.getBytes());
outputStream.flush();
exchange.close();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;sendResponseHeaders(200, length) sets the HTTP status code (200 OK) and the response length.&lt;/p&gt;

&lt;p&gt;getResponseBody() gives you an output stream to write data back to the client.&lt;/p&gt;

&lt;p&gt;Always remember to flush() and close() the connection to avoid memory leaks.&lt;/p&gt;

&lt;p&gt;🌍 Step 4: Testing the API&lt;/p&gt;

&lt;p&gt;Once you run the program, you’ll see:&lt;/p&gt;

&lt;p&gt;Server started on port 8080&lt;/p&gt;

&lt;p&gt;Now open your browser or use curl to test your endpoints:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl http://localhost:8080/api/hello&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Hello World!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And for the second endpoint:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl http://localhost:8080/api/world&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Thanks for connecting with the world!&lt;br&gt;
💡 Step 5: What You Just Built&lt;/p&gt;

&lt;p&gt;You’ve just built a fully functional REST API — from scratch — without using any frameworks.&lt;br&gt;
This simple code can handle multiple routes, validate request methods, and send back responses, all powered by Java’s standard library.&lt;/p&gt;

&lt;p&gt;Here’s what’s exciting:&lt;/p&gt;

&lt;p&gt;No Spring Boot overhead.&lt;/p&gt;

&lt;p&gt;No hidden configuration.&lt;/p&gt;

&lt;p&gt;You directly control request handling.&lt;/p&gt;

&lt;p&gt;This is how you start thinking like a 1% developer — by understanding the fundamentals before relying on abstraction.&lt;/p&gt;

&lt;p&gt;🚀 What’s Next?&lt;/p&gt;

&lt;p&gt;Now that you’ve built a raw HTTP server:&lt;/p&gt;

&lt;p&gt;Try adding POST and DELETE endpoints.&lt;/p&gt;

&lt;p&gt;Parse JSON requests using com.google.gson or org.json.&lt;/p&gt;

&lt;p&gt;Implement basic routing and middleware (like authentication).&lt;br&gt;
Step by step, you’ll see how frameworks like Spring Boot evolved from these very basics.&lt;/p&gt;

&lt;p&gt;❤️ Final Thoughts&lt;/p&gt;

&lt;p&gt;Becoming a 1% developer isn’t about memorizing libraries — it’s about mastering the core concepts that power them.&lt;br&gt;
When you know how to build an API without Spring Boot, you gain a whole new appreciation for what frameworks do for you — and more importantly, you know how to fix things when they break.&lt;/p&gt;

&lt;p&gt;So keep experimenting. Break things. Learn how they work.&lt;br&gt;
That’s the real developer mindset.&lt;/p&gt;

&lt;p&gt;If you found this useful, give it a clap 👏 and share it with your developer friends who love to learn the real stuff.&lt;/p&gt;

</description>
      <category>java</category>
      <category>spring</category>
      <category>springboot</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
