项目作者: aziz781

项目描述 :
Sample Customer Rest API
高级语言: Java
项目地址: git://github.com/aziz781/customer-api.git
创建时间: 2020-01-26T13:52:33Z
项目社区:https://github.com/aziz781/customer-api

开源协议:Apache License 2.0

下载


Customer REST API

Sample Customer Rest API using Spring Boot and Apache Camel

  1. 1. Spring Boot: v2.2.2
  2. 2. Apache Camel: v3.0.0
  3. 3. Java: v1.8
  4. 4. Maven: v3.6.0
  5. 5. Junit jupiter: v5.5.2
  6. 6. springfox-swagger2: v2.8.0
  7. 7. springfox-swagger-ui: v2.8.0
  8. 8. Docker
  9. 9. Git
  10. 10.Json

Clone the application

  1. git clone https://github.com/aziz781/customer-api.git

Three ways to Build & Run

1. Maven

Build

  1. mvn package

Run

  1. java -jar target/customer-api-1.0.0.jar

Alternatively, you can run the app without packaging it using

Build & Run

  1. mvn spring-boot:run

2. Docker

Build

  1. docker build -t aziz781/customer-api .

Run

  1. docker run -d -p 8080:8080 -t aziz781/customer-api

3. Docker-compose

Build & Run

  1. docker-compose up

How to use Customer Rest API

The app will start running locally at http://localhost:8080

API Documentation

The API documentation at http://localhost:8080/swagger-ui.html

API Resource
The API expose the the following resource

  1. POST /api/v1/customers

API URL

The POST endpoint for customer registration.

  1. http://localhost:8080/api/v1/customers

Request Payload

The sample request JSON payload for Customer Rest API.

Frontend Json

  1. {
  2. "firstName": "Abdul",
  3. "lastName": "Aziz",
  4. "phone": "0123456789",
  5. "email": "customer@sample.com"
  6. }
  • The frontend json is validated using frontend schema
  • The frontend json is Transformed to backend json
  • The backend json is validated against backend schema

NOTE:
The transformation is implemented using camel Jolt component to process a JSON messages using an JOLT specification. This is for JSON to JSON transformation.

Backend Json

  1. {
  2. "userFirstName": "Abdul",
  3. "userLastName": "Aziz",
  4. "contact":{
  5. "phoneNumber": "0123456789",
  6. "emailAddress": "customer@sample.com"
  7. }
  8. }

Mock Backend service at http://localhost:9001/registrations
Mock service is implemented using Camel Rest DSL with Netty HTTP component to facilitiate HTTP transport.

Responses

201

  1. {
  2. "status": "SUCCESS",
  3. "message": "Customer registered successfully"
  4. }

400

  1. {
  2. "status": "ERROR",
  3. "message": "firstName: is missing but it is required"
  4. }

400

  1. {
  2. "status": "ERROR",
  3. "message": "firstName: must be at least 3 characters long"
  4. }

400

  1. {
  2. "status": "ERROR",
  3. "message": "Invalid Json Format"
  4. }

CURL

  1. curl -i -X POST "http://localhost:8080/api/v1/customers" -H "accept: application/json" -H "Content-Type: application/json" -d ""
  2. HTTP/1.1 400
  3. Content-Type: application/json
  4. {"status":"ERROR","message":"Invalid Json Format"}
  1. curl -i -X POST "http://localhost:8080/api/v1/customers" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"firstName\": \"\", \"lastName\": \"greatman\", \"phone\": \"012345678\", \"email\": \"tester@api.com\" }"
  2. HTTP/1.1 400
  3. Content-Type: application/json
  4. {"status":"ERROR","message":"firstName: is missing but it is required"}
  1. curl -i -X POST "http://localhost:8080/api/v1/customers" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"firstName\": \"my\", \"lastName\": \"greatman\", \"phone\": \"012345678\", \"email\": \"tester@api.com\" }"
  2. HTTP/1.1 400
  3. Content-Type: application/json
  4. {"status":"ERROR","message":"firstName: must be at least 3 characters long"}
  1. curl -i -X POST "http://localhost:8080/api/v1/customers" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"firstName\": \"tester\", \"lastName\": \"greatman\", \"phone\": \"012345678\", \"email\": \"tester@api.com\" }"
  2. HTTP/1.1 201
  3. Content-Type: application/json
  4. {"status":"SUCCESS","message":"Customer registered successfully"}

Docker Hub

  1. docker pull aziz781/customer-api:latest