TechWriterDev
  • Cloud
    • AWS
      • 00_Doubts
      • CloudPractitioner
        • Cloud Computing
        • AWS Global Infrastructure
        • Introduction to AWS EC2
        • Elastic load balancer(ELB)
        • 04_Messaging_Queuing
        • Aditional Computing Service
        • Accessing AWS resources
        • AWS Networking
        • Storage
        • Amazon Database Solutions
        • Monitoring Tools
        • AWS Security
        • Distributed Denial Of Service Attacks
      • DeveloperAssociate
        • References
        • AWS DVA-C02 Services Index
        • Services
          • 00_IAM
            • Identity and Access Management (IAM)
            • Account Protection Mechanisms
            • Access Mechanism of AWS Resources
            • Security Tools
            • Responsibility Model
            • Advanced Concepts
          • 01_EC2
            • Elastic Compute Cloud (EC2)
            • EC2 Volume Types
            • Amazon Machine Image (AMI)
            • AWS charges for IPv4 address
          • 02_SecurityGroups
            • Security Groups
          • 03_Elastic_LoadBalancing
            • Terminology
            • Elastic load balancer
            • Features
            • Basics
          • 04_AutoScaling
            • Auto Scaling
          • 05_RDS
            • Relational Database Service (RDS)
            • Aurora
            • Security
            • RDS Proxy
          • 06_ElastiCache
            • Cache
            • Cache Offerings
          • 07_Route53
            • Basics of DNS
            • Route 53
          • 08_VPC
            • Virtual Private Cloud (VPC)
          • 09_S3
            • Simple Storage Service (S3)
            • S3 Features
            • S3 Encryption
            • S3 Features
            • S3 Bucket Policy and IAM Policy
          • 10_ECS
            • Elastic Container Service (ECS)
            • Elastic Container Registry (ECR)
            • AWS Copilot
          • 11_EKS
            • Elastic Kubernetes Service (EKS)
          • 12_SDK_CLI_Tips
            • Access AWS Resources
          • 13_CloudFront
            • Cloud Front
          • 14_Messaging
            • Simple Queue Service (SQS)
            • Simple Notification Service (SNS)
            • Fan Out Pattern
            • Kinesis
            • Compare and Contrast
          • 15_ElasticBeanStalk
            • Elastic Beanstalk
          • 16_CloudFormation
            • CloudFormation
            • Dynamic References
          • 17_Monitoring
            • AWS Monitoring
            • AWS CloudWatch
            • CloudWatch Alarms
            • Synthetics Canary
            • Amazon EventBridge (formerly CloudWatch Events)
            • X-Ray
            • OpenTelemetry
            • CloudTrail
          • 18_Lambda
            • Lambda
            • Lambda Integrations
            • Configuring Lambda
            • Lambda Layers
          • 19_API_Gateway
            • API Gateway
            • API Gateway Integrations
          • 20_DynamoDB
            • DynamoDB
            • Operations
            • Indexes
            • DynamoDB Accelerator (DAX)
            • DynamoDB Streams
            • Transactions
            • Integrations
          • 21_CICD
            • CICD
            • CodeCommit
            • CodePipeline
            • CodeBuild
            • CodeDeploy
            • CodeArtifact
            • CloudGuru
          • 22_SAM
            • Serverless Application Model (SAM)
          • 23_CDK
            • Cloud Development Kit (CDK)
          • 24_StepFunctions
            • Step Functions
            • Types of step function
          • 25_AppSync
            • AppSync
          • 26_Amplify
            • Amplify
          • 27_STS
            • Security Token Service (STS)
          • 28_DirectoryService
            • Active Directory
          • 29_KMS
            • Encryption
            • KMS API
            • Features
            • Cloud Hardware Security Module (HSM)
          • 30_SSM_Store
            • SSM Parameter Store
          • 31_SecretsManager
            • Secrets Manager
          • 32_Cognito
            • Cognito
      • Questions
        • AWS_Region
        • EC2
        • IAM
  • Database
    • MongoDb
      • Mongo db Basics
      • Mongo DB Atlas
      • Document
      • Import-Export based on Data Format
      • Mongo Shell Commands
      • Query Operators
      • Indexes
      • Upsert
      • MongoDB Aggregation Framework
      • Aggregation Framework Operators
    • PostgreSQL
      • POSTGRE SQL DataTypes
      • About table
      • Constraints
  • Technologies
    • RabbitMQ
      • RabbitMQ Concepts
      • Introduction to Exchanges
      • Introduction to Queues
    • Terraform
      • 00_Introduction
      • Configuration blocks
      • Commands
      • Variables
      • Terraform Cloud
      • Modules
  • Languages
    • Java
      • Logging
        • Getting Started
      • 00_Core
        • 00_Basics
          • Java Vs C++
          • Object oriented principles
          • Steps to compile a java program
          • JVM Internals
          • Understanding Java Development Kit
          • What is JIT Compiler?
          • Java data types
          • 07_identifiers_type_conversion
          • 08_references_and_packages
          • Steps for attaching scanner
        • Concurrency
          • 00_Threads
            • Threads
          • 01_ExecutorFramework
            • Executor Framework
            • Asynchronous Computation
      • 01_Backend
        • 01_HttpAndWebServerBasics
          • HTTP
          • Content Type
          • Web Server
        • 02_J2EE_Basics
          • J2EE_Basics
          • Why HttpServlet classs is declared as abstract class BUT with 100 % concrete functionality ?
        • 03_TomCatAndSession
          • What is a Session?
          • WebContainer
        • 04_PageNavigation
          • Cookies Additional Information
          • Page Navigation Techniques
        • 05_AboutServlet
          • CGI v/s Servlet
          • Executor Framework
          • Servlet Life cycle
          • SERVLET CONFIG
          • Servlet Context
          • Servlet Listener (web application listener)
        • 08_SpringBoot
          • Spring Boot
          • Some common annotations used in spring eco system
        • 09_SpringDataJPA
          • Spring Data JPA
        • Java_Language_Changes
          • JDK enhancement tracking reference
        • 06_ORM_Hibernate
          • readmes
            • Hibernate
            • Advantages of Hibernate
            • Hibernate Caching
            • Hibernate API
            • Hibernate Query API
            • Hibernate Annotations and JPQL
            • Entity and Value Type
        • 07_SpringFramework
          • bean_validation
            • Bean Validation
          • core
            • readme
              • Spring
              • Spring Framework Modules
              • Spring MVC Request flow
              • Dependency Injection
              • Spring Beans
              • 06_Spring_Framework_Annotations
      • 03_Tools
        • Maven
          • Maven
  • SoftwareEngineering
    • DesignPatterns
      • Notes
        • Basics
        • OOP
        • SOLID Principles
        • 03_Creational
          • Abstract Factory (aka Kit)
          • Builder
          • Factory Method (aka Virtual constructor)
          • Prototype
          • Singleton
        • 04_Structural
          • Adapter (aka Wrapper)
          • Bridge (aka Handle | Body)
          • Composite
          • Decorator (aka Wrapper)
          • Facade
          • Flyweight
          • Proxy (aka Surrogate)
        • 05_Behavioral
          • Chain of Responsibility
          • Command (aka Action | Transaction)
          • Iterator (aka Cursor)
          • Observer (aka Publish-Subscribe | Dependents)
          • Strategy (aka Policy)
    • Principles
      • REST
        • REST
  • Tools
    • Containers
      • Docker
        • Docker
        • Docker Image
        • Commands
        • Compose
        • Best Practices
      • Kubernetes
        • Kubernetes
    • VCS
      • Git
        • Quick reference of useful Git commands
Powered by GitBook
On this page
  • HTTP request methods and Headers
  • HTTP request methods
  • HTTP Response
  • Safe HTTP methods
  • Idempotent HTTP methods
  • HTTP method overview
  1. Languages
  2. Java
  3. 01_Backend
  4. 01_HttpAndWebServerBasics

HTTP

  • HTTP stands for Hyper Text Transfer Protocol which is an application level protocol for transferring textual data between client and server.

  • HTTP is stateless protocol.

  • Web Client such as web browser sends the request to server, server responds and sends the requested data (such as a HTML document) or returns error code and closes the connection. Once the response is returned, server doesn't remember anything about the client (even the very next request).

HTTP request methods and Headers

  • URL: http://www.server.com:8080/bank/login.html

  • Whenever the client sends the request to server for any resource such as a HTML document, it specifies

    1. HTTP method (get/post/put/delete....)

    2. Request URI (eg : /bank/login.html)

    3. Protocol version

    4. Optional Header information (eg : accept, cookies)

  • After the client sends the request, server processes the request and sends the response.

HTTP request methods

  • The request method indicates to the server what action to perform on the resource identified by the request-URI.

  • HTTP 1.1 specifies these request methods, GET, POST , HEAD,OPTIONS, PUT, TRACE, DELETE, CONNECT.

  • Servlets can process any of the above requests. But GET and POST methods are most commonly used.

  • The GET request method is safe (doesn't change state of the resource) & idempotent (repeated requests do not have any further side effects after the first request).

  • The GET request is used typically for getting static information from the server such as HTML document, images, and CSS files. It can be used to retrieve dynamic information also by appending query string at the end of request URI.

The POST request

  • The POST request is typically used to access OR create new dynamic resources.

  • POST request is used to,

    1. Send the large amount of data to the server.

    2. Upload files to servers

    3. Send serializable Java objects or raw bytes.

GET v/s POST

  1. GET request sends the request parameters as query string appended at the end of the request URL, whereas POST request sends the request parameters as part of the HTTP request body.

  2. Unlike GET, POST request sends all the data as part of the HTTP request body, so it doesn't appear in browser address bar and cannot be bookmarked.

  3. GET is non-secure, whereas POST is secure.

  4. GET is idempotent whereas POST is not idempotent.

  5. Typically use GET requests to retrieve resource from server.

  6. User POST to change some state on server (something like update or create).

  7. Some web servers limit the length of the URL. So, if in GET request, too many parameters are appended in query string and URL exceeds this length, some web servers might not accept the request. For POST, we can put request body limit.

Query String

  • Query string is used to pass additional request parameters along with the request.

  • Query string format

        URL?name1=value1&name2=value&name3=value3...
    • For example,

        http://www.abc.com/test/login.jsp?userid=10&name=abc&age=25

HTTP Response

  1. Response status information (eg : 404/200)

  2. Response headers (eg : cookies, content-type: text/html, content-length)

  3. Response data.

    • Following is an example of HTTP request which uses GET request method to ask for a HTML document named tutorial.html using HTTP protocol version 1.1

        GET /tutorial.html HTTP/1.1
    • Following is the example of request header, which provides additional information about the request.

        User-Agent: Mozilla/4.0 (compatible; MSIE 4.0; Windows 95)
        Accept: image/gif, image/jpeg, text/*,...
    • Above header specifies the information about the client software and what MIME (Multi-purpose Internet Mail Extension) type the client accepts in response, using User-Agent and Accept headers.


Note: Idempotency and safety are properties of HTTP methods.

Safe HTTP methods

  • HTTP methods are considered safe if they do not alter the server state. So safe methods can only be used for read-only operations. The HTTP specifications define the following methods to be safe.

    • GET, HEAD, OPTIONS and TRACE.

  • In practice, it is often not possible to implement safe methods in a way that they do not alter any server state.

    • For example, a GET request might create log or audit messages, update statistic values or trigger a cache refresh on the server.

  • The RFC states,

    • Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.

Idempotent HTTP methods

  • Idempotency means that multiple identical requests will have the same outcome. So it does not matter if a request is sent once or multiple times. The following HTTP methods are idempotent,

    • GET, HEAD, OPTIONS, TRACE, PUT and DELETE.

  • All safe HTTP methods are idempotent but PUT and DELETE are idempotent but not safe.

  • Note that idempotency does not mean that the server has to respond in the same way on each request.

    • For example, assume we want to delete a project by an ID using a DELETE request:

        DELETE /projects/123 HTTP/1.1
    • As a response, we might get an HTTP 200 status code indicating that the project has been deleted successfully. If we send this DELETE request again, we might get an HTTP 404 as response because the project has already been deleted. The second request did not alter the server state so the DELETE operation is idempotent even if we get a different response.

  • Idempotency is a positive feature of an API because it can make an API more fault-tolerant. Assume there is an issue on the client and requests are send multiple times. As long as idempotent operations are used this will cause no problems on the server side.

HTTP method overview

The following table summarizes which HTTP methods are safe and idempotent:

HTTP Method
Safe
Idempotent

GET

Yes

Yes

HEAD

Yes

Yes

OPTIONS

Yes

Yes

TRACE

Yes

Yes

PUT

No

Yes

DELETE

No

Yes

POST

No

No

PATCH

No

No

Previous01_HttpAndWebServerBasicsNextContent Type

Last updated 4 months ago