Əsas məzmuna keçin

HTTP və HTTPS

HTTP Nədir?

HTTP (HyperText Transfer Protocol) - World Wide Web-də data mübadiləsi üçün istifadə olunan application layer protokoludur.

Xüsusiyyətlər:

  • Stateless - hər request müstəqildir
  • Text-based - human-readable format
  • Client-Server model - request/response pattern
  • Port 80 - default port
  • TCP üzərində işləyir

HTTP Request Structure

Nümunə Request:

GET /api/users/123 HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0
Accept: application/json
Authorization: Bearer token123

HTTP Methods

GET

Məqsəd: Resource-u əldə etmək

  • Idempotent: Bəli
  • Safe: Bəli (dəyişiklik etmir)
  • Cacheable: Bəli
  • Body: Yox
GET /api/users HTTP/1.1
Host: api.example.com

POST

Məqsəd: Yeni resource yaratmaq

  • Idempotent: Xeyr
  • Safe: Xeyr
  • Cacheable: Şərti
  • Body: Bəli
POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
"name": "Tural",
"email": "tural@example.com"
}

PUT

Məqsəd: Resource-u tamamilə dəyişdirmək

  • Idempotent: Bəli
  • Safe: Xeyr
  • Cacheable: Xeyr
  • Body: Bəli
PUT /api/users/123 HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
"id": 123,
"name": "Tural Updated",
"email": "tural.new@example.com"
}

PATCH

Məqsəd: Resource-u qismən dəyişdirmək

  • Idempotent: Xeyr (method-dan asılı)
  • Safe: Xeyr
  • Cacheable: Xeyr
  • Body: Bəli
PATCH /api/users/123 HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
"email": "tural.new@example.com"
}

DELETE

Məqsəd: Resource-u silmək

  • Idempotent: Bəli
  • Safe: Xeyr
  • Cacheable: Xeyr
  • Body: Xeyr (optional)
DELETE /api/users/123 HTTP/1.1
Host: api.example.com

Məqsəd: GET kimi, amma yalnız headers qaytarır

  • Metadata əldə etmək üçün
  • Resource mövcudluğunu yoxlamaq

OPTIONS

Məqsəd: Server-in dəstəklədiyi method-ları öyrənmək

  • CORS preflight requests
  • API discovery
OPTIONS /api/users HTTP/1.1
Host: api.example.com

HTTP Methods Flow

HTTP Status Codes

1xx - Informational

CodeMeaningAçıqlama
100ContinueServer request-in ilk hissəsini qəbul edib
101Switching ProtocolsProtocol dəyişdirilir (WebSocket)

2xx - Success

CodeMeaningAçıqlama
200OKRequest uğurlu oldu
201CreatedYeni resource yaradıldı
202AcceptedRequest qəbul edildi, amma hələ process olunur
204No ContentUğurlu, amma content yoxdur

3xx - Redirection

CodeMeaningAçıqlama
301Moved PermanentlyResource daimi olaraq köçürülüb
302FoundMüvəqqəti redirect
304Not ModifiedCache-dəki versiya актуaldır
307Temporary RedirectMüvəqqəti redirect, method dəyişməz
308Permanent RedirectDaimi redirect, method dəyişməz

4xx - Client Error

CodeMeaningAçıqlama
400Bad RequestSəhv request formatı
401UnauthorizedAuthentication lazımdır
403ForbiddenAccess rədd edildi
404Not FoundResource tapılmadı
405Method Not AllowedHTTP method dəstəklənmir
409ConflictKonflikt (məs: duplicate)
429Too Many RequestsRate limit aşıldı

5xx - Server Error

CodeMeaningAçıqlama
500Internal Server ErrorServer-də xəta baş verdi
502Bad GatewayGateway/proxy səhv cavab aldı
503Service UnavailableServer müvəqqəti əlçatmazdır
504Gateway TimeoutGateway timeout

HTTP Response Structure

Nümunə Response:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 85
Cache-Control: max-age=3600
Set-Cookie: session=abc123; HttpOnly

{
"id": 123,
"name": "Tural",
"email": "tural@example.com"
}

HTTP Headers

Request Headers

Host:

Host: www.example.com

User-Agent: Client məlumatı

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)

Accept: Qəbul edilən content type-lar

Accept: application/json, text/html
Accept-Language: az, en
Accept-Encoding: gzip, deflate

Authorization: Authentication məlumatı

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Authorization: Basic dXNlcjpwYXNzd29yZA==

Cookie: Client-side cookies

Cookie: session=abc123; user_id=456

Content-Type: Request body-nin tipi

Content-Type: application/json
Content-Type: application/x-www-form-urlencoded
Content-Type: multipart/form-data

Response Headers

Content-Type: Response body-nin tipi

Content-Type: application/json; charset=utf-8

Content-Length: Body-nin ölçüsü (bytes)

Content-Length: 1234

Set-Cookie: Cookie set etmək

Set-Cookie: session=abc123; HttpOnly; Secure; SameSite=Strict

Cache-Control: Caching directives

Cache-Control: max-age=3600, public
Cache-Control: no-cache, no-store, must-revalidate

Location: Redirect URL

Location: https://example.com/new-location

ETag: Resource versiyası

ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"

HTTPS (HTTP Secure)

HTTPS = HTTP + SSL/TLS

Xüsusiyyətlər:

  • Encryption: Data şifrələnir
  • Authentication: Server identity doğrulanır
  • Integrity: Data dəyişdirilmədiyini təmin edir
  • Port 443: Default port

SSL/TLS Handshake

SSL/TLS Versions

VersionİlStatus
SSL 1.0-Never released
SSL 2.01995Deprecated (2011)
SSL 3.01996Deprecated (2015)
TLS 1.01999Deprecated (2020)
TLS 1.12006Deprecated (2020)
TLS 1.22008✅ Current
TLS 1.32018✅ Recommended

Certificate Chain

HTTP/2

Təkmilləşdirmələr:

  • Binary protocol - text əvəzinə binary
  • Multiplexing - bir connection-da çox request
  • Server Push - server proaktiv olaraq data göndərir
  • Header compression - HPACK algoritmi
  • Stream prioritization - prioritet sistemi

HTTP/1.1 vs HTTP/2

FeatureHTTP/1.1HTTP/2
ProtocolText-basedBinary
ConnectionsMultipleSingle multiplexed
HeaderPlain text, repetitiveCompressed (HPACK)
Server PushNoYes
PrioritizationNoYes
PerformanceGoodBetter

HTTP/3 (QUIC)

Əsas fərqlər:

  • UDP üzərində (TCP əvəzinə)
  • 0-RTT connection - daha sürətli
  • Improved loss recovery
  • Connection migration - IP dəyişikliklərinə davamlı

Caching

Cache-Control Directives

Request directives:

Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: max-age=3600

Response directives:

Cache-Control: public, max-age=86400
Cache-Control: private, max-age=3600
Cache-Control: no-cache, no-store, must-revalidate

Caching Flow

ETag və Conditional Requests

First Request:

GET /api/users/123 HTTP/1.1
Host: api.example.com

HTTP/1.1 200 OK
ETag: "686897696a7c876b7e"
Content-Type: application/json

{"id": 123, "name": "Tural"}

Subsequent Request:

GET /api/users/123 HTTP/1.1
Host: api.example.com
If-None-Match: "686897696a7c876b7e"

HTTP/1.1 304 Not Modified

CORS (Cross-Origin Resource Sharing)

Məqsəd: Cross-origin requests-ə icazə vermək/rədd etmək.

Simple Request

Preflight Request

CORS Headers:

Access-Control-Allow-Origin: https://example.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 86400
Access-Control-Allow-Credentials: true

Cookies

Cookie Attributes:

Set-Cookie: session=abc123; Domain=example.com; Path=/; Max-Age=3600; Secure; HttpOnly; SameSite=Strict

Attributes:

  • Domain: Cookie-nin keçərli olduğu domain
  • Path: Cookie-nin keçərli olduğu path
  • Max-Age/Expires: Expiration time
  • Secure: Yalnız HTTPS üzərində
  • HttpOnly: JavaScript-dən əlçatmaz
  • SameSite: CSRF qorunması (Strict, Lax, None)

Authentication

Basic Authentication

GET /api/users HTTP/1.1
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

Dezavantajlar:

  • Credentials hər request-də göndərilir
  • Base64 encoding (encryption deyil)
  • HTTPS lazımdır

Bearer Token (JWT)

GET /api/users HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Üstünlüklər:

  • Stateless
  • Self-contained
  • Scalable

OAuth 2.0 Flow

REST API Best Practices

1. Resource-based URLs:

✅ GET /api/users
✅ POST /api/users
✅ GET /api/users/123
✅ PUT /api/users/123
✅ DELETE /api/users/123

❌ GET /api/getUsers
❌ POST /api/createUser

2. Use HTTP Methods correctly:

  • GET - Read
  • POST - Create
  • PUT - Full update
  • PATCH - Partial update
  • DELETE - Delete

3. Use Status Codes properly:

  • 2xx - Success
  • 4xx - Client error
  • 5xx - Server error

4. Versioning:

/api/v1/users
/api/v2/users

5. Filtering, Sorting, Pagination:

GET /api/users?role=admin&sort=name&page=2&limit=20

Performance Optimization

1. Compression:

Accept-Encoding: gzip, deflate, br
Content-Encoding: gzip

2. Keep-Alive:

Connection: keep-alive
Keep-Alive: timeout=5, max=100

3. Conditional Requests:

If-None-Match: "etag-value"
If-Modified-Since: Wed, 21 Oct 2020 07:28:00 GMT

4. HTTP/2 Server Push:

Link: </styles.css>; rel=preload; as=style

Security Best Practices

  1. Həmişə HTTPS istifadə et

  2. HSTS header:

    Strict-Transport-Security: max-age=31536000; includeSubDomains
  3. Security Headers:

    X-Content-Type-Options: nosniff
    X-Frame-Options: DENY
    X-XSS-Protection: 1; mode=block
    Content-Security-Policy: default-src 'self'
  4. Rate Limiting:

    X-RateLimit-Limit: 100
    X-RateLimit-Remaining: 75
    X-RateLimit-Reset: 1635789600
  5. Input Validation və Sanitization

  6. CORS düzgün konfiqurasiya

  7. Sensitive data header-larda göndərmə

Əlaqəli Mövzular

  • TCP/IP Protocol
  • DNS System
  • Load Balancing
  • CDN
  • Network Security
  • API Design
  • WebSockets