PHP code example of veasin / nx-tools

1. Go to this page and download the library: Download veasin/nx-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

veasin / nx-tools example snippets


use nx\annotations\http\Client;
use nx\annotations\router\Get;
use nx\annotations\router\REST;
#[
    Client(Var:[
        'port'=>"8081",
    ]),
    Get("/user/d:uid", "get"),
    Client(Route:['put', '/user'],
        Throw: [404,401, 200],
        Return: ['id'=>'ID','nick-name'=>['name'=>'Nick Name', 'type'=>'string'],'email'=>'EMail'],
        Note: "Login",
        Response: [
            'body'=>['id'=>'user-id', 'corp-id'=>'corp-id'],
            'header'=>['token'=>'token'],
        ],
        Var: [
            'auth-token'=>"TOKEN id={{user-id}};token={{token}}"
        ],
    ),
    Client('get', '/user/{{user-id}}',
        Route:['get', '/user/d:uid', 'get'],
        Auth: "{{auth-token}}",
        Note: "Get User By ID",
    ),
    REST("/console/user", "/d:user_id", "list,add,get,update,delete"),
    Client(
        Route: ['rest', "/console/user", "/d:user_id", "list,add,get,update,delete"],
        Auth: "{{auth-token}}",
        Note: "Console Users"
    )
]
class user{
   	#[Get("/debug/ok")]
   	#[Client('get', '/debug/ok', Throw: [200], Note: "测试", Test: ['status'=>[200=>'OK']])]
	public function ok(): void{
	
	}
	#[Client(Route: ['get', '/debug/ok2'], Throw: [200], Note: "测试", Test: ['status'=>[200=>'OK']])]
	public function ok2(): void{
	    $this->out('ok');
	}
}