Skip to content

Instantly share code, notes, and snippets.

View bcarun's full-sized avatar

Arun B Chandrasekaran bcarun

View GitHub Profile
HTTP STATUS CODE USAGE
200 Ok Resource created and returned
200 Ok Resource updated and returned
200 Ok Resource patched and returned
200 Ok Resource deleted
200 Ok Request processed successfully
201 Created Resource created and location header returned
202 Accepted Request will be processed asynchronously
204 No Content Request processed successfully and there is no response payload
@bcarun
bcarun / rest-api-best-practices_http-method-use-cases.md
Last active December 28, 2019 20:38
Rest API Best Practices Snippet - HTTP Method Usage
USE CASE HTTP METHOD
Create POST
Get or Find GET
Update PUT
Partial Update PATCH
Delete or Soft Delete DELETE
Search POST
List Of Values GET
@bcarun
bcarun / rest-api-best-practices_http-user-input-failure-status-code-usages.md
Last active November 25, 2018 05:13
Rest API Best Practices - HTTP Status Codes for user invalid user input
HTTP STATUS CODE USAGE
400 Bad Request Input validation failed
400 Bad Request JSON payload or request is unparsable
401 Unauthorized Require authorization header
404 Not Found No data exist for given input
409 Conflict When optimistic lock fails (User tries to update stale version)
412 Precondition Failed Constraint violation occurred
@bcarun
bcarun / rest-api-best-practices_http-system-input-failure-status-code-usages.md
Last active November 25, 2018 05:50
REST API Best Practices - HTTP Status Codes For System Failure
HTTP STATUS CODE EXAMPLE USAGE
500 Internal Server Error Unexpected system failure
500 Internal Server Error Unexpected failure during database call
500 Internal Server Error Micro-service to micro-service call failed
500 Internal Server Error Auth server (Keycloak/Okta) call failed
503 Service Unavailable Database is down
504 Gateway Timeout Depending micro-service is not up
import java.time.LocalDate;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "patient_profile")
public class PatientProfile {
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter
public class StringMapConverter implements AttributeConverter<Map<String, String>, String> {
CREATE TABLE patient_profile (
id int,
first_name varchar(45),
last_name varchar(45),
date_of_birth date,
-- -------------------------------
-- Custom Attributes
attribute_1 varchar(255),
attribute_2 varchar(255),
-- -------------------------------
CREATE TABLE patient_profile (
id int,
first_name varchar(45),
last_name varchar(45),
date_of_birth date,
-- -------------------------------------------
-- Custom Attributes
other_attributes json, -- JSON Datatype Column
-- -------------------------------------------
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.oauth2.resource.JwtAccessTokenConverterConfigurer;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;