Giter Site home page Giter Site logo

cart-spring-boot-api's Introduction

Spring Boot Lesson

Quick Start

To run the project:

Step 1: CD to the project root directory cart_api

Step 2: Run ./mvnw spring-boot:run command

Lesson Overview (24 Feb 2023, Fri)

Previously, we have

  • Create a spring starter project with web dependency here
  • Used several annotations to create RESTful API
@RestController
@RequestMapping
@RequestBody
@ResponseBody
@PathVariable
@Autowired
@Service

In this lesson, we will cover:

  1. Configure a custom singleton object using @Bean annotation
  2. The use of @Value annotation to inject environmental variable
  3. Implementing a logger to capture all API Input

Essentially, there are three common ways to configure and inject Spring Bean/Value.

  1. Using @Component or its children - @RestController, @Service, etcs..
  2. Using @Value to inject value picked up from application.properties file.
  3. Using @Bean on a method that returns a configured object.

Practically, we will create this endpoint:

Path Verb Return Status Remarks
/payment?payable=5.3 POST 200 Payment successful
400 When payment is below minimum payable sum or negative value.

Lesson Overview (20 Feb 2023, Mon)

  1. Generate a Spring Project with the web dependency added
  2. Annotations Explanations:
    • @SpringBootApplication
    • @RestController
    • @RequestMapping
    • @RequestBody
    • @RequestResponse

By the end of the class, we would have created:

  1. GET /products
  2. GET /products/{id}
  3. POST /products
  4. PUT /products/{id}
  5. DELETE /products/{id}

Standard REST API

Path Verb Has Request Body Has Response Body Purpose
/entities GET NO YES Get all entities (usually with pagination and sorting query parameters)
/entities/{id} GET NO YES Get one entity by id
/entities POST Yes YES Create an entity
/entities/{id} PUT YES YES Update an entity
/entities/{id} DELETE NO NO Delete an entity

For more info - Link

cart-spring-boot-api's People

Contributors

edisonzsq avatar acetay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.