Apakah 200 baik atau buruk?

Dalam artikel tiga menit ini, saya ingin menyentuh subjek yang sakit.

Kami akan berbicara tentang status kode HTTP 200 dan kesalahan dalam respons.

HTTP/1.1 200 OK

{
  "error": {
    code: 2019,
    message: "Validation failed: field 'size' is invalid: the value is not a number"
  }
}

, ?

? ? - .

whaaat

1. HTTP 200 batch


. . 200. . . batch ?


, . API .

:

{
  "sources": [
    {"image": "http://myserver.com/image1.jpg"},
    {"image": "http://myserver.com/image2.jpg"},
    {"video": "http://myserver.com/video.jpg"}
  ]
}

, - (, ) . ? 2xx 4xx 5xx? , :

HTTP/1.1 200 OK

{
  "results": [
    { "status": "ok", "id": 312 },
    { "status": "ok", "id": 313 },
    { "status": "fail", "error": "NO SPACE" }
  ]
}

( ) . 200. , .

2. HTTP 200


. . , - . , . - 200! .

- github bitbucket, . . «» . .

. :

β€” C, API. . . Β«errorΒ», .
β€” 4xx 5xx! ?!
β€” -. . . , . , , .
β€” …

HTTP 200 β€”


200 200. . . . ?! json !

, . ? ? ? ?

- . . . . .

Source: https://habr.com/ru/post/id440382/


All Articles