🚀 Day 30/100 - Spring Boot - Handling Request Parameters When building REST APIs, handling client input correctly is key. Spring Boot provides a few powerful annotations for this 👇 ➡️ @PathVariable 🔹Binds a URL path segment to a method parameter 🔹Example: /users/{id} → @PathVariable Long id 🔹Used when the value is part of the URL itself ➡️ @RequestParam 🔹Extracts query parameters from the URL 🔹Example: /users?role=admin → @RequestParam String role 🔹Best for optional filters, search params, pagination, etc ➡️ @RequestBody 🔹Maps the request body (JSON/XML) directly to a Java object 🔹Example: JSON POST → @RequestBody User user 🔹Commonly used in POST/PUT APIs ➡️ Why this matters 🔹Clean API contracts 🔹Automatic data binding 🔹Less manual parsing 🔹Readable and maintainable code Next post: https://lnkd.in/dRHkuPyT Previous post: https://lnkd.in/da4MExJy #100Days #SpringBoot #Java #RESTAPI #PathVariable #RequestParam #RequestBody #BackendDevelopment #WebDevelopment #SoftwareEngineering
Mahreen Asama’s Post
More Relevant Posts
-
Hi everyone 👋 📌 Spring Boot Annotation Series Part 22– @RequestParam @RequestParam is used to read query parameters from the request URL and bind them to method parameters. It is part of the Spring Framework and commonly used in REST APIs built with Spring Boot. 🔹 Why do we use @RequestParam? Sometimes we need to pass additional information through the URL. Example: GET /users?age=25 Here, age is a query parameter. @RequestParam helps us capture that value in the controller method. 🔹 Simple Example @RestController @RequestMapping("/users") public class UserController { @GetMapping("/search") public String getUserByAge(@RequestParam int age) { return "User age is: " + age; } } 👉 Request URL: GET http://localhost:8080/users/search?age=25 Output: User age is: 25 🔹 In Simple Words @RequestParam takes values from query parameters in the URL and passes them to the controller method. 👉 🧠 Quick Understanding Used in filtering, search APIs Can be optional using required=false Can provide default values Used to read query parameters from URL Mostly used in GET APIs #SpringBoot #Java #RESTAPI #RequestParam #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
Hi everyone 👋 📌 Spring Boot Annotation Series Part 18 – @PostMapping The @PostMapping annotation is used to handle HTTP POST requests in a Spring Boot application. It is part of the Spring Framework and is mainly used to create new resources in REST APIs. 🔹 What is @PostMapping? @PostMapping is a shortcut for: @RequestMapping(method = RequestMethod.POST) It makes the code cleaner and more readable. 🔹 When Do We Use POST? ✔ To create new data ✔ To submit form data ✔ To send request body (JSON/XML) ✔ When data is modified on the server Example use cases: Create a new user Place an order Register a customer Submit login details 🔹 Basic Example - @RestController @RequestMapping("/api/users") public class UserController { @PostMapping public String createUser(@RequestBody String user) { return "User created: " + user; } } 👉 Handles: POST http://localhost:8080/api/users 🔹 In Simple Words @PostMapping handles create operations in REST APIs. When a POST request hits the URL, Spring executes the mapped method and processes the request body. #SpringBoot #Java #RESTAPI #BackendDevelopment #InterviewPreparation #LearningInPublic
To view or add a comment, sign in
-
📌 Spring Boot Annotation Series Part 17 – @GetMapping The @GetMapping annotation is used to handle HTTP GET requests in Spring Boot applications. It is part of the Spring Framework and is mainly used in REST APIs. 🔹 What is @GetMapping? @GetMapping is a shortcut for: @RequestMapping(method = RequestMethod.GET) Instead of writing the long version, we use this cleaner and more readable annotation. 🔹 Basic Example - @RestController @RequestMapping("/api") public class UserController { @GetMapping("/users") public String getUsers() { return "List of users"; } } 👉 This handles: GET http://localhost:8080/api/users 🔹 When Do We Use GET? ✔ To fetch data ✔ No modification of data ✔ Safe and idempotent operation Example use cases: - Get all users - Get user by ID - Fetch product list - Retrieve order details 🔹 In Simple Words @GetMapping handles read operations in REST APIs. When a GET request hits the URL, Spring executes the mapped method. #SpringBoot #Java #RESTAPI #BackendDevelopment #InterviewPreparation #LearningInPublic
To view or add a comment, sign in
-
📌 Spring Boot Annotation Series Part 19 – @DeleteMapping @DeleteMapping is used to handle HTTP DELETE requests in a REST API. It is part of Spring Framework and is commonly used in RESTful services built with Spring Boot. 🔹 Why Do We Use @DeleteMapping? In REST APIs: GET → Fetch data POST → Create data PUT → Update data DELETE → Remove data @DeleteMapping handles delete operations. 🔹 What Happens Internally? @DeleteMapping is a shortcut for: @RequestMapping(method = RequestMethod.DELETE) So it is a specialized version of @RequestMapping. 🔹 In Simple Words @DeleteMapping connects an HTTP DELETE request to a controller method to remove a resource. #SpringBoot #Java #RESTAPI #DeleteMapping #BackendDevelopment #InterviewPreparation
To view or add a comment, sign in
-
Recently, I stopped “using” Spring Boot and started understanding it. At first, building a REST API felt easy. Controller. Service. Repository. Done. But as the system grew, real engineering problems showed up: Slow endpoints. N+1 queries. Lazy loading errors. Circular dependencies. Bloated service classes. Security confusion with JWT and filter chains. So I stepped back and studied what was actually happening underneath. I read about: • Dependency Injection and Inversion of Control • How JPA and Hibernate generate SQL • Proper transaction boundaries with @Transactional • DTO vs Entity design • Connection pooling and indexing • Clean Architecture principles Then I started applying it. I moved transactions to the service layer. Replaced entity exposure with DTOs. Used fetch joins to fix N+1 queries. Reduced tight coupling by separating responsibilities. Analyzed SQL logs instead of guessing. The biggest lesson: Spring Boot makes it easy to build. But scaling an API forces you to think about design, boundaries, and tradeoffs. Frameworks don’t create clean systems. Engineers do. Still learning. Still refactoring. Still optimizing. #SpringBoot #Java #BackendDevelopment #SoftwareEngineering #CleanArchitecture #SystemDesign #APIDesign #Microservices #Developers
To view or add a comment, sign in
-
-
☕🎸 JAVA VS GROOVY: 10 JVM FEATURES IN CODE ⏭️Swipe the carousel below 👇 🔸 TL;DR ▪️ Java: explicit, strongly typed, predictable for large teams, “standard” tooling ✅ ▪️ Groovy: concise, scripting-friendly, great for DSLs (Gradle, Spock), optional typing 🚀 ▪️ Both run on the JVM — choice depends on whether you optimize for safety & uniformity (Java) or speed & expressiveness (Groovy). 🔸 TAKEAWAYS 🎯 ▪️ Groovy often looks like “no boilerplate”: default public, optional semicolons/parentheses, auto-imports 😄 ▪️ For core APIs (time, I/O, i18n), Groovy typically uses the same Java libraries, just with terser syntax. ▪️ Choose Java for: long-lived services, strict contracts, easier onboarding at scale ✅ ▪️ Choose Groovy for: build logic, tests (Spock), automation scripts, readable DSLs ⚡ ▪️ Mixing both can be powerful: Java for prod code, Groovy for tooling + tests 🔧 #Java #Groovy #JVM #SoftwareEngineering #Backend #BuildTools #Gradle #Maven #Testing #Spock #Concurrency #Streams #I_O #Localization #DeveloperProductivity Go further with Java certification: Java👇 https://lnkd.in/eZKYX5hP Spring👇 https://lnkd.in/eADWYpfx SpringBook👇 https://bit.ly/springtify JavaBook👇 https://bit.ly/jroadmap
To view or add a comment, sign in
-
🚀 Spring Boot Daily Learning Are you using @Component on every class and wondering why Spring gives you 4 different stereotype annotations? Here's what actually separates them — and why it matters in production. Spring's stereotype annotations all register beans in the IoC container, but they carry different semantic weight and unlock different framework features: @Component // Generic bean — use as last resort @Service // Business logic layer @Repository // Data access layer + exception translation @Controller // MVC presentation layer (with @RestController for REST) The critical difference? @Repository activates Spring's PersistenceExceptionTranslationPostProcessor — it automatically translates low-level JPA/Hibernate exceptions into Spring's unified DataAccessException hierarchy. Your service layer never leaks Hibernate internals. @Service and @Controller signal architectural intent. Spring AOP, Spring Security, and your teammates all rely on these contracts to apply cross-cutting concerns correctly. Using @Component everywhere breaks that contract. Best practice: Always pick the most specific annotation. @Component is for custom infrastructure beans — not business or data code. #Java #SpringBoot #BackendDevelopment #SpringFramework #CleanCode
To view or add a comment, sign in
-
@Autowired & @Qualifier in Spring Framework 👇 In the Spring Framework, @Autowired and @Qualifier are used for Dependency Injection. 🔹 @Autowired @Autowired is used to automatically inject dependencies into a class. The Spring IoC container finds and connects the required bean without manually creating objects using new. ✅ Why use @Autowired? Reduces boilerplate code Removes manual object creation Supports loose coupling Makes code cleaner and more readable 📌 Where can we use @Autowired? On Constructor (Recommended ✅) On Setter methods On Fields 🔹 @Qualifier @Qualifier is used along with @Autowired when multiple beans of the same type exist. It helps Spring identify which exact bean should be injected. ✅ Why use @Qualifier? Resolves ambiguity Provides better control over bean selection Makes configuration more precise 📌 Where can we use @Qualifier? In class-based (annotation-based) configuration On Constructor parameters On Setter methods On Fields 👉 In simple words: @Autowired performs injection @Qualifier selects the correct bean Together, they make Spring applications clean, flexible, and well-structured. 📚 Currently learning & implementing concepts step by step. #Spring #Autowired #Qualifier #DependencyInjection #IOC #SpringFramework #Java #BackendDevelopment #JavaFullStack #Day13_Adv_Java
To view or add a comment, sign in
-
-
🚀 Spring Boot Developers — stop memorizing. Start recognizing. Most Spring Boot bugs don’t come from missing annotations. They come from not knowing which annotation does what under the hood. So I put together a battle-tested Spring Boot Annotation Cheatsheet covering 70+ essential annotations across 10 real-world categories 👇 --- 📌 What you’ll master (and stop Googling forever): 🧩 Component Scanning & DI → @Autowired, @Qualifier, @Primary (and when each one actually matters) ⚙️ Configuration & Beans → @Configuration, @Bean, @Lazy 🌐 Spring MVC & REST → All HTTP mapping annotations that power real APIs 🗄️ Spring Data JPA → Entity mappings, relationships, and persistence essentials 🔐 Spring Security → @PreAuthorize, @Secured, @RolesAllowed 🧬 Microservices → @FeignClient, @EnableEurekaClient, @CircuitBreaker 🧪 Testing → @SpringBootTest, @MockBean, @DataJpaTest 🎭 AOP → @Aspect, @Before, @After, @Around ⚡ Caching → @Cacheable, @CachePut, @CacheEvict ✅ Validation → @NotBlank, @Email, @Pattern --- 💡 Reality check: Framework mastery isn’t about using more annotations. It’s about using the right one at the right layer. Bookmark this. Your future self debugging at 2 AM will thank you. 👇 Which Spring Boot annotation do you use the most — and why? Let’s compare notes. 🔁 Repost if this helps your Java circle ➕ Follow Pondurai Madheswaran for daily Java & Spring insights #PonduraiWrites #SpringBoot #Java #BackendDevelopment #SoftwareEngineering #SpringFramework #JavaDevelopment #Microservices #DeveloperTips
To view or add a comment, sign in
-
💬 A friend asked me to check his Spring Boot API today — it kept returning 400 Bad Request. The JSON looked correct. The endpoint looked fine. Still failing. After 2 minutes, I spotted the issue 👇 He forgot to add @RequestBody in the controller method. @PostMapping("/users") public ResponseEntity<?> createUser(@RequestBody User user) { return ResponseEntity.ok(service.save(user)); } 👉 Why this matters? Spring Boot doesn’t automatically convert incoming JSON into Java objects. @RequestBody tells Spring: “Take the HTTP request body → deserialize JSON → map it to this object.” Without it: ❌ Object stays null ❌ Request mapping fails ❌ You get 400 Bad Request Small annotation… but critical for REST APIs. Moments like this remind me — backend development is often about understanding how the framework works internally, not just writing code. Learning something new every day with Spring Boot 🚀 #Java #SpringBoot #BackendDeveloper #FullStackDeveloper #RESTAPI #CodingLife #BugFix #SoftwareEngineering #Developers #TechLearning
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development