Download the PHP package yadakhov/okdata without Composer
On this page you can find all versions of the php package yadakhov/okdata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yadakhov/okdata
More information about yadakhov/okdata
Files in yadakhov/okdata
Package okdata
Short Description A wrapper class for the OkData json api specifications.
License MIT
Homepage https://github.com/yadakhov/okdata
Informations about the package okdata
OkData json api response
OkData is inspired by the jsend api response specifications.
The motivation for the specifications is to have json api responses that looks like:
Note to two keys: ok and data which is why the spec is called OkData.
Required and optional keys for each type:
Ok Status | Description | Required Keys | Optional Keys |
---|---|---|---|
true | All went well, and (usually) some data was returned. | ok, data | |
false | An error occurred in processing the request, i.e. an exception was thrown | ok, error | data |
Example response types
GET /posts.json:
GET /posts/2.json:
DELETE /posts/2.json:
Required keys:
- ok: Should always be set true
- data: Acts as the wrapper for any data returned by the API call. If the call returns no data (as in the last example), data should be set to null.
Error
When an API call fails due to an error on the server. For example:
GET /posts.json:
Required keys:
- ok: Should always be set false.
- error: A meaningful, end-user-readable (or at the least log-worthy) message, explaining what went wrong.
Optional keys:
- data: A generic container for any other information about the error, i.e. the conditions that caused the error, stack traces, etc.
What's the different between OkData and JSend?
OkData uses a boolean status ok. JSend uses three statuses: success, fail, and error. In my experience, we only use success, and error.
The boolean ok status also makes it easier to check. if (json.ok) { }