<?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: Dhawal Nil</title>
    <description>The latest articles on DEV Community by Dhawal Nil (@dhawal_nil).</description>
    <link>https://dev.to/dhawal_nil</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%2F3565950%2F759bac15-33f7-4c92-a7ff-fa15a0c9be4e.png</url>
      <title>DEV Community: Dhawal Nil</title>
      <link>https://dev.to/dhawal_nil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dhawal_nil"/>
    <language>en</language>
    <item>
      <title>⚡ I Built a REST API in 15 Minutes Using Spring Boot — Here’s How You Can Too</title>
      <dc:creator>Dhawal Nil</dc:creator>
      <pubDate>Wed, 15 Oct 2025 06:45:43 +0000</pubDate>
      <link>https://dev.to/dhawal_nil/i-built-a-rest-api-in-15-minutes-using-spring-boot-heres-how-you-can-too-37ca</link>
      <guid>https://dev.to/dhawal_nil/i-built-a-rest-api-in-15-minutes-using-spring-boot-heres-how-you-can-too-37ca</guid>
      <description>&lt;p&gt;When I first started learning backend development, the idea of creating an API felt like rocket science 🚀. But once I discovered Spring Boot, everything clicked — it’s simple, powerful, and saves tons of time.&lt;br&gt;
In this article, I’ll walk you through building a fully functional REST API using Spring Boot and MySQL, step by step. No unnecessary theory — just clean, working code you can try right now.&lt;/p&gt;

&lt;p&gt;🎯 What You’ll Learn&lt;br&gt;
By the end of this guide, you’ll know how to:&lt;br&gt;
Create a Spring Boot project from scratch&lt;br&gt;
Build REST endpoints (GET, POST, PUT, DELETE)&lt;br&gt;
Connect your app to a MySQL database&lt;br&gt;
Test the API using Postman&lt;/p&gt;

&lt;p&gt;🛠️ Step 1: Set Up Your Project&lt;br&gt;
Go to Spring Initializr and generate your project.&lt;br&gt;
Choose these options:&lt;br&gt;
Project: Maven&lt;br&gt;
Language: Java&lt;br&gt;
Spring Boot: 3.x&lt;br&gt;
Dependencies: Spring Web, Spring Data JPA, MySQL Driver&lt;br&gt;
Download the zip, extract it, and open it in your IDE (IntelliJ, Eclipse, or VS Code).&lt;/p&gt;

&lt;p&gt;⚙️ Step 2: Configure Your Database&lt;br&gt;
Edit the application.properties file like this:&lt;br&gt;
spring.datasource.url=jdbc:mysql://localhost:3306/student_db&lt;br&gt;
spring.datasource.username=root&lt;br&gt;
spring.datasource.password=yourpassword&lt;br&gt;
spring.jpa.hibernate.ddl-auto=update&lt;br&gt;
spring.jpa.show-sql=true&lt;/p&gt;

&lt;p&gt;👩‍💻 Step 3: Create the Student Entity&lt;br&gt;
Create Student.java in the model package:&lt;br&gt;
package com.example.demo.model;&lt;/p&gt;

&lt;p&gt;import jakarta.persistence.*;&lt;/p&gt;

&lt;p&gt;@Entity&lt;br&gt;
@Table(name = "students")&lt;br&gt;
public class Student {&lt;br&gt;
    &lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;&lt;br&gt;
    @GeneratedValue(strategy = GenerationType.IDENTITY)&lt;br&gt;
    private Long id;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private String name;
private String email;
private int age;

// Getters and Setters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;💾 Step 4: Add a Repository&lt;br&gt;
Create a repository interface:&lt;br&gt;
package com.example.demo.repository;&lt;/p&gt;

&lt;p&gt;import org.springframework.data.jpa.repository.JpaRepository;&lt;br&gt;
import com.example.demo.model.Student;&lt;/p&gt;

&lt;p&gt;public interface StudentRepository extends JpaRepository {&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;🌐 Step 5: Build the REST Controller&lt;br&gt;
Now, expose CRUD endpoints:&lt;br&gt;
package com.example.demo.controller;&lt;/p&gt;

&lt;p&gt;import com.example.demo.model.Student;&lt;br&gt;
import com.example.demo.repository.StudentRepository;&lt;br&gt;
import org.springframework.web.bind.annotation.*;&lt;br&gt;
import java.util.List;&lt;/p&gt;

&lt;p&gt;@RestController&lt;br&gt;
@RequestMapping("/api/students")&lt;br&gt;
public class StudentController {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private final StudentRepository repo;

public StudentController(StudentRepository repo) {
    this.repo = repo;
}

@GetMapping
public List&amp;lt;Student&amp;gt; getAllStudents() {
    return repo.findAll();
}

@PostMapping
public Student addStudent(@RequestBody Student student) {
    return repo.save(student);
}

@PutMapping("/{id}")
public Student updateStudent(@PathVariable Long id, @RequestBody Student updatedStudent) {
    return repo.findById(id)
            .map(student -&amp;gt; {
                student.setName(updatedStudent.getName());
                student.setEmail(updatedStudent.getEmail());
                student.setAge(updatedStudent.getAge());
                return repo.save(student);
            })
            .orElseThrow(() -&amp;gt; new RuntimeException("Student not found"));
}

@DeleteMapping("/{id}")
public String deleteStudent(@PathVariable Long id) {
    repo.deleteById(id);
    return "Student deleted successfully!";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;🧪 Step 6: Test Your API&lt;br&gt;
Run your app and test using Postman or curl:&lt;br&gt;
GET /api/students → Fetch all students&lt;br&gt;
POST /api/students → Add a new student&lt;br&gt;
PUT /api/students/{id} → Update a student&lt;br&gt;
DELETE /api/students/{id} → Delete a student&lt;/p&gt;

&lt;p&gt;💡 Bonus: Add Global Error Handling&lt;br&gt;
Make your API error messages cleaner:&lt;br&gt;
@RestControllerAdvice&lt;br&gt;
public class GlobalExceptionHandler {&lt;br&gt;
    @ExceptionHandler(RuntimeException.class)&lt;br&gt;
    public ResponseEntity handleRuntimeException(RuntimeException ex) {&lt;br&gt;
        return new ResponseEntity&amp;lt;&amp;gt;(ex.getMessage(), HttpStatus.NOT_FOUND);&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;🚀 Wrapping Up&lt;br&gt;
You just built your first working REST API using Spring Boot and MySQL in under 15 minutes. From here, you can:&lt;br&gt;
Add validation with &lt;a class="mentioned-user" href="https://dev.to/valid"&gt;@valid&lt;/a&gt;&lt;br&gt;
Add JWT-based security&lt;br&gt;
Deploy your app on Render or Railway for free&lt;br&gt;
Spring Boot makes backend development fun and fast. Keep experimenting — every project will make you better! 🙌&lt;/p&gt;

&lt;p&gt;🏷️ Tags&lt;/p&gt;

&lt;h1&gt;
  
  
  java #springboot #backend #tutorial #webdev
&lt;/h1&gt;

</description>
      <category>springboot</category>
      <category>api</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
  </channel>
</rss>
