DEV Community

Tejasvi Urkande
Tejasvi Urkande

Posted on

πŸ“… Week 2 – Spring Boot Web & REST API Fundamentals

This week, I continued my journey into Spring Boot and focused on building REST APIs, understanding dependency injection in depth, and testing APIs with Postman.

πŸ”Ή Dependency Injection & @Autowired

Explored dependency injection (DI) further.
Constructor injection β†’ Clean, works without @Autowired.
Field injection β†’ Needs @Autowired to inject object references.

@Autowired tells Spring to find the right bean by type and inject it automatically, making the code loosely coupled and easier to test.

πŸ’‘ Mistake I made:
Initially tried manually creating objects like in core Java. This broke IoC. Learned to always let Spring manage object creation.

Also explored Spring XML Config to define beans manually. While annotations make life easier now, knowing XML configuration is useful for fundamentals and interviews.

πŸ”Ή Spring Boot Web & REST APIs

Learned to create REST APIs using @RestController & @RequestMapping.

Discovered that @RestController combines @Controller + @ResponseBody, so we don’t need to manually add @ResponseBody.

Used @RequestMapping to map endpoints like /api/hello and handle requests.

πŸ’‘ Problem I faced:
Using @Controller without @ResponseBody caused the API to return a view error. Switching to @RestController fixed it.

Learned the DispatcherServlet flow: Spring receives HTTP requests, routes them to the correct controller, and returns a response.

πŸ”Ή HTTP Methods & Postman Practice

Learned HTTP methods for REST APIs:
β€’ GET β†’ Retrieve data from the server.
β€’ POST β†’ Send data to the server to create new resources.

Practiced sending requests and receiving responses using Postman.
Learned to use @RequestBody for POST requests to handle JSON input.

πŸ’‘ Mistake I made:
Forgot @RequestBody initially β†’ POST data wasn’t received properly. Postman helped me debug quickly.

βœ… Week 2 Takeaways

  1. Understood dependency injection in detail (@Autowired, constructor vs field injection).
  2. Explored Spring XML configuration to understand legacy bean management.
  3. Built REST APIs efficiently using @RestController & @RequestMapping.
  4. Learned HTTP methods (GET, POST) and tested APIs with Postman.
  5. Understood the DispatcherServlet request flow.
  6. Identified common mistakes and learned how to fix them.

πŸ’‘ Why I’m Sharing:
Documenting my weekly progress helps me retain knowledge and also helps other beginners avoid common pitfalls while learning Spring Boot.

Java #SpringBoot #RESTAPI #DependencyInjection #FullStackDevelopment #BackendDevelopment #100DaysOfCode

Top comments (1)

Collapse
 
anh_nguyen_ce4f9fd2029bcf profile image
Anh Nguyen

keep track on you