Skip to content

Commit

Permalink
📝 docs: update README with examples for v1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezajavadigit committed Jun 27, 2024
1 parent f18cf5a commit 1c86056
Showing 1 changed file with 93 additions and 43 deletions.
136 changes: 93 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -16,69 +16,119 @@ composer require alirezajavadi/jsonize

Once JSONize is installed, you can start using it in your projects. Here's a basic example of how to use JSONize:

# New Features in v1.5.1

#### Easy Syntax

For a more straightforward syntax, use:

```php
<?php
//init
use JSONize\App\Response;

$response = Response::getInstance();
//
use JSONize\App\Easy\Response;

// Examples:
// Example 1: Success
Response::message("Deleted Successfully");
/*
{
"success": true,
"message": "Deleted Successfully",
"data": null,
"status": [
200,
"ok"
]
}
*/

// 1. Success Example
$response->message("Deleted SuccessFully")->end();
// Example 2: Error
Response::message("User Not Found")->status(404);
/*
result
{
"success": true,
"message": "Deleted SuccessFully",
"data": null,
"status": [
200,
"ok"
]
}
{
"success": false,
"message": "User Not Found",
"data": null,
"status": [
404,
"Not Found"
]
}
*/

// 2. Error Example
$response->message("User Not Found")->status(404)->end();
// Example 3: No Content
Response::status(204);
/*
result
{
"success": false,
"message": "User Not Found",
"data": null,
"status": [
404,
"Not Found"
]
}
{
"success": true,
"message": null,
"data": null,
"status": [
204,
"No Content"
]
}
*/
```

#### Efficient Memory Usage

For efficient usage and memory safety, use:

```php
<?php
//init
use JSONize\App\Efficient\Response;

$response = Response::getInstance();

// Example 1: Success
$response->message("Deleted Successfully")->end();
/*
{
"success": true,
"message": "Deleted Successfully",
"data": null,
"status": [
200,
"ok"
]
}
*/

// 3. Other Example
$response->status(204)->end();
// Example 2: Error
$response->message("User Not Found")->status(404)->end();
/*
result
{
"success": true,
"message": null,
"data": null,
"status": [
204,
"No Content"
]
}
{
"success": false,
"message": "User Not Found",
"data": null,
"status": [
404,
"Not Found"
]
}
*/

// Example 3: No Content
$response->status(204)->end();
/*
note the end() is important to use;
{
"success": true,
"message": null,
"data": null,
"status": [
204,
"No Content"
]
}
*/
// Note: `end()` is important to use.

```

### Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you encounter any problems or have suggestions for improvements.
Contributions are welcome! Everyone who wants to contribute can add new HTTP status codes to this file: System/Traits/HasStatus.php. Submit a pull request or open an issue for any problems or suggestions.

### License

0 comments on commit 1c86056

Please sign in to comment.