{"id":20145909,"url":"https://github.com/usagi/usagi.php","last_synced_at":"2025-08-24T19:06:47.947Z","repository":{"id":57076050,"uuid":"67010564","full_name":"usagi/usagi.php","owner":"usagi","description":"Usagi's PHP library; http, CouchDB","archived":false,"fork":false,"pushed_at":"2016-09-12T11:05:55.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T11:11:21.351Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usagi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-31T06:38:09.000Z","updated_at":"2016-08-31T08:53:18.000Z","dependencies_parsed_at":"2022-08-24T14:55:48.080Z","dependency_job_id":null,"html_url":"https://github.com/usagi/usagi.php","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fusagi.php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fusagi.php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fusagi.php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fusagi.php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usagi","download_url":"https://codeload.github.com/usagi/usagi.php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241587845,"owners_count":19986628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T22:18:41.565Z","updated_at":"2025-03-03T00:14:24.342Z","avatar_url":"https://github.com/usagi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Usagi's PHP library\n\n# Features\n\n## 0. include all features in the library\n\n```php\n// for direct downloaded\nrequire_once 'usagi.php/source/http.php'\n// or, for composer\n//require_once 'vendor/usagi/usagi.php/source/all.php'\n```\n\nnote 1: this library refused to abide by PSR, thus set to 'files' mode to the composer.\nnote 2: you can include indivisual part of this library.\n\n## 1. http wrapper\n\n```php\n// for direct downloaded\nrequire_once 'usagi.php/source/http.php'\n// or, for composer\n```\n\n### 1.1. http library // stateles, simple and convinient\n\n#### GET\n\n```php\n// a simple GET request\nvar_dump( \\usagi\\http\\request( 'http://php.net' ) );\n```\n\n```php\narray(3) {\n  [\"status_code\"]=\u003e\n  int(200)\n  [\"headers\"]=\u003e\n  array(11) {\n    [\"Server\"]=\u003e\n    string(11) \"nginx/1.6.2\"\n    [\"Date\"]=\u003e\n    string(29) \"Wed, 31 Aug 2016 08:27:02 GMT\"\n    [\"Content-Type\"]=\u003e\n    string(24) \"text/html; charset=utf-8\"\n    [\"Connection\"]=\u003e\n    string(5) \"close\"\n    [\"X-Powered-By\"]=\u003e\n    string(19) \"PHP/5.6.24-0+deb8u1\"\n    [\"Last-Modified\"]=\u003e\n    string(29) \"Wed, 31 Aug 2016 08:10:14 GMT\"\n    [\"Content-language\"]=\u003e\n    string(2) \"en\"\n    [\"X-Frame-Options\"]=\u003e\n    string(10) \"SAMEORIGIN\"\n    [\"Set-Cookie\"]=\u003e\n    string(102) \"LAST_NEWS=1472632022; expires=Thu, 31-Aug-2017 08:27:02 GMT; Max-Age=31536000; path=/; domain=.php.net\"\n    [\"Link\"]=\u003e\n    string(36) \"\u003chttp://php.net/index\u003e; rel=shorturl\"\n    [\"Vary\"]=\u003e\n    string(15) \"Accept-Encoding\"\n  }\n  [\"content\"]=\u003e\n  string(21472) \"\u003c!DOCTYPE html\u003e\n\u003chtml xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\"\u003e\n\u003chead\u003e\n...\n}\n```\n\n#### HEAD, DELETE, ...\n\n```php\n$response = \\usagi\\http\\request( 'http://example.net', 'HEAD' ) );\n$response = \\usagi\\http\\request( 'http://example.net', 'DELETE' ) );\n```\n\n#### PUT, POST, ...\n\n```php\n$response = \\usagi\\http\\request( 'http://example.net', 'PUT' , $data ) );\n$response = \\usagi\\http\\request( 'http://example.net', 'POST', $data ) );\n```\n\n#### add custom headers\n\n```php\n$response = \\usagi\\http\\request\n  ( 'http://example.net'\n  , 'PUT'\n  , $data\n  , [ 'x-my-custom-request-header-1' =\u003e 'custom value 1'\n    , 'x-my-custom-request-header-2' =\u003e 'custom value 2'\n    ]\n  );\n```\n\n#### with convinient stateless helpers\n\n```php\necho \\usagi\\http\\make_url( 'http', 'example.net', '12345' );\n```\n\n\u003e http://example.net:12345\n\n```php\necho \\usagi\\http\\make_url\n  ( 'http'\n  , 'example.net'\n  , '12345'\n  , [ 'path1', 'path2', 'path3   ' ]\n  );\n```\n\n\u003e http://example.net:12345/path1/path2/path3%20%20%20\n\n```php\necho \\usagi\\http\\make_url\n  ( 'http'\n  , 'example.net'\n  , '12345'\n  , [ 'path1', 'path2', 'path3   ' ]\n  , [ 'q1_key' =\u003e 'q1_value', 'q2_key' =\u003e 'q2_value' ]\n  );\n```\n\n\u003e http://example.net:12345/path1/path2/path3%20%20%20?q1_key=q1_value\u0026q2_key=q2_value\n\nand etc.\n\n## 2. CouchDB library\n\n```php\nrequire_once 'usagi.php/source/couchdb.php'\n// or, for composer\n//require_once 'vendor/usagi/usagi.php/source/couchdb.php'\n```\n\n### 2.1. stateless library // for a simple usecases\n\n```php\nrequire_once 'usagi.php/source/couchdb/stateless.php'\n```\n\n#### get version infos\n\n```php\nvar_dump( \\usagi\\couchdb\\get_version( 'http', '127.0.0.1', 5984 ) );\n```\n\n```php\narray(4) {\n  [\"couchdb\"]=\u003e\n  string(7) \"Welcome\"\n  [\"uuid\"]=\u003e\n  string(32) \"4fa79ddb179218126c1245256d74878f\"\n  [\"version\"]=\u003e\n  string(5) \"1.6.1\"\n  [\"vendor\"]=\u003e\n  array(2) {\n    [\"version\"]=\u003e\n    string(5) \"16.04\"\n    [\"name\"]=\u003e\n    string(6) \"Ubuntu\"\n  }\n}\n```\n\n#### database features\n\n```php\n$is_exists = \\usagi\\couchdb\\is_exists_database( 'http', '127.0.0.1', 5984, 'test' );\n$is_succeeded = \\usagi\\couchdb\\create_database( 'http', '127.0.0.1', 5984, 'test' );\n$is_succeeded = \\usagi\\couchdb\\delete_database( 'http', '127.0.0.1', 5984, 'test' );\n```\n\n#### document features\n\n```php\n// rev or FALSE\n$rev = \\usagi\\couchdb\\is_exists_document( 'http', '127.0.0.1', 5984, 'test', 'd1' );\n\n// get data with decoded to a PHP array from a JSON result\n$php_array_data = usagi\\couchdb\\get_document( 'http', '127.0.0.1', 5984, 'test2', 'd1' ) );\n\n// create document\n$id_and_rev = \\usagi\\couchdb\\create_document( 'http', '127.0.0.1', 5984, 'test2', 'd1', $omissible_your_php_array_data );\n\n// delete document\n$is_succeeded = \\usagi\\couchdb\\delete_document( 'http', '127.0.0.1', 5984, 'test2', 'd1' );\n\n// update document\n$id_and_rev = \\usagi\\couchdb\\update_document( 'http', '127.0.0.1', 5984, 'test2', 'd1', [ 'hoge' =\u003e 'fuga' ] );\n```\n\n##### document attachment features\n\n```php\n// attach\n$is_succeeded = \\usagi\\couchdb\\attach_document( 'http', '127.0.0.1', 5984, 'test2', 'd1', 'somthing.png' );\n\n// detach\n$is_succeeded = \\usagi\\couchdb\\detach_document( 'http', '127.0.0.1', 5984, 'test2', 'd1', 'something.png' ) );\n\n// attachment header infos with rev included or FALSE\n$rev_and_header_infos = \\usagi\\couchdb\\is_exists_attachment( 'http', '127.0.0.1', 5984, 'test2', 'd1', 'something.png' ) );\n\n// get attachment binary\nfile_put_contents( 'somthing.png', \\usagi\\couchdb\\get_attachment( 'http', '127.0.0.1', 5984, 'test2', 'd1', 'something.png' ), LOCK_EX );\n```\n\n### 2.2. statefull library // function chain, auto memorize parameters, auto result queueing\n\n```php\nrequire_once 'usagi.php/source/couchdb/statefull.php'\n// or, for composer\n//require_once 'vendor/usagi/usagi.php/source/couchdb/statefull.php'\n```\n\n```php\n$c1 = new \\usagi\\couchdb\\statefull;\n\n// save parameters implicit\n// and functions are chainable\n// and results are auto stacked/queued and exportable anythime!\n\n$c1 -\u003e set_auto_memorize_parameters( true ) // enabling auto memorize parameters, default is true\n    -\u003e get_document( 'document1', 'database1', 5984, '127.0.0.1', 'http' ) // queue result to results[ 0 ]\n    -\u003e shift_result( $x ) // move results[ 0 ] to $x ( remove results[ 0 ] and data be set to $x )\n    -\u003e get_document( 'document2' ) // result[ 0 ]\n    -\u003e get_attachment( 'attachemnet2-1.png' ) // result[ 1 ]\n    -\u003e get_document( $x['foobar'] ) // result[ 2 ]\n    -\u003e peek_result( 0, $y ) // copy result[ 0 ] to $y ( result[ 0 ] be not delete )\n    -\u003e get_document( $x['foobar'], 'databse2' ) // result[ 3 ]\n    -\u003e get_document( $x['foobar'], 'databse3' ) // result[ 4 ]\n    -\u003e get_document( $x['foobar'], 'databse4' ) // result[ 5 ]\n    ;\n\n// this will be out 5 results\nvar_dump( $c-\u003eresults )\n```\n\n# License\n\n[MIT](LICENSE)\n\n# Author\n\nUsagi Ito\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusagi%2Fusagi.php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusagi%2Fusagi.php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusagi%2Fusagi.php/lists"}