Recommend this page to a friend! |
Download .zip |
Info | Example | View files (62) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2023-09-13 (3 days ago) | Not yet rated by the users | Total: 28 This week: 28 | All time: 10,906 This week: 5 |
Version | License | PHP version | Categories | |||
httpsnippet 1.0.0 | MIT/X Consortium ... | 7 | HTTP, Code Generation, PHP 7 |
Description | Author | |
This package can generate code snippets to make HTTP requests. |
httpsnippet
is a PHP package that enables you to make HTTP request codes for any language. This can be particularly useful for developers who are looking to perform HTTP requests using various programming languages.
Here?s how you can create a GET request code in PHP:
$request = new \IsaEken\HttpSnippet\Request(
method: 'GET',
uri: 'https://example.com'
);
echo \IsaEken\HttpSnippet\HttpSnippet::make($request, 'php.curl')->toString();
You can install this package via composer:
composer require isaeken/httpsnippet
The httpsnippet
package allows you to create HTTP request codes in various programming languages. Below are the steps to use this package:
Before you start, make sure that you have installed the package via composer. If not, you can install it by running:
composer require isaeken/httpsnippet
Now, import the httpsnippet package in your PHP script:
use IsaEken\HttpSnippet\HttpSnippet;
use IsaEken\HttpSnippet\Request;
require_once __DIR__ . '/vendor/autoload.php';
Next, create a request object. You can do this by passing the request method, URI, headers, and body to the Request
class:
$request = new Request(
method: 'GET',
uri: 'https://example.com',
headers: [
'Accept' => 'application/json',
],
body: [
'foo' => 'bar',
],
version: '1.1',
cookies: [
'foo' => 'bar',
],
);
Now, use the make method of the HttpSnippet class to generate the request code for the desired programming language. Pass in the request object and the target programming language as parameters.
$code = HttpSnippet::make($request, 'language.identifier');
For instance, to generate the code in PHP using cURL, you would do:
$code = HttpSnippet::make($request, 'php.guzzle');
You can now output or use the generated code as needed. For example, to print the code:
echo $code->toString();
// output:
// <?php
//
// $client = new \GuzzleHttp\Client();
//
// $response = $client->request(
// 'GET',
// 'https://example.com',
// [
// 'body' => '{"foo":"bar"}',
// 'headers' => [
// "Accept" => "application/json",
// "Cookie" => "foo=bar",
// ],
// ],
// );
//
// echo $response->getBody();
Or, to save the code to a file:
file_put_contents('code.txt', $code->toString());
The following languages and identifiers are supported:
| Language | Identifier | Ready for use? |
| --- |----------------------------|----------------|
| C | libcurl
| ? |
| C# | csharp.httpclient
| ? |
| C# | csharp.restsharp
| ? |
| PHP | php.curl
| ? |
| PHP | php.guzzle
| ? |
| Shell | shell.curl
| ? |
| Shell | shell.wget
| ? |
Run the tests with:
composer test
All notable changes to httpsnippet
will be documented in this file
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email hello@isaeken.com.tr instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Files |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
bin (1 file) | ||||
config (1 file) | ||||
src (4 files, 6 directories) | ||||
tests (3 files, 1 directory) | ||||
.editorconfig | Data | Auxiliary data | ||
.php_cs.dist.php | Example | Example script | ||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE.md | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Read me |
Files | / | .github | / | workflows |
File | Role | Description |
---|---|---|
php-cs-fixer.yml | Data | Auxiliary data |
run-tests.yml | Data | Auxiliary data |
update-changelog.yml | Data | Auxiliary data |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Abstracts (1 file) | ||||
Contracts (1 file) | ||||
Enums (1 file) | ||||
Exceptions (1 file) | ||||
Languages (4 directories) | ||||
Traits (3 files, 1 directory) | ||||
CodeGenerator.php | Class | Class source | ||
helpers.php | Aux. | Helper script | ||
HttpSnippet.php | Class | Class source | ||
Request.php | Class | Class source |
Files | / | src | / | Languages | / | CSharp |
File | Role | Description |
---|---|---|
HttpClient.php | Class | Class source |
RestSharp.php | Class | Class source |
Files | / | src | / | Languages | / | Php |
File | Role | Description |
---|---|---|
Curl.php | Class | Class source |
Guzzle.php | Class | Class source |
Files | / | src | / | Traits |
File | Role | Description | ||
---|---|---|---|---|
Request (7 files) | ||||
HasHttpSnippet.php | Class | Class source | ||
HasLanguage.php | Class | Class source | ||
HasRequest.php | Class | Class source |
Files | / | src | / | Traits | / | Request |
File | Role | Description |
---|---|---|
HasBody.php | Class | Class source |
HasCookies.php | Class | Class source |
HasHeaders.php | Class | Class source |
HasMethod.php | Class | Class source |
HasProtocolVersion.php | Class | Class source |
HasRequestTarget.php | Class | Class source |
HasUri.php | Class | Class source |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
snippets (2 directories) | ||||
CodeGeneratorTest.php | Class | Class source | ||
RequestTest.php | Class | Class source | ||
UnitTest.php | Class | Class source |
Files | / | tests | / | snippets | / | basic |
File | Role | Description |
---|---|---|
c.libcurl.txt | Doc. | Documentation |
csharp.httpclient.txt | Doc. | Documentation |
csharp.restsharp.txt | Doc. | Documentation |
php.curl.txt | Doc. | Documentation |
shell.curl.txt | Doc. | Documentation |
shell.wget.txt | Doc. | Documentation |
Files | / | tests | / | snippets | / | php | / | guzzle |
File | Role | Description |
---|---|---|
application-form-encoded.php | Example | Example script |
application-json.php | Example | Example script |
cookies.php | Example | Example script |
custom-method.php | Example | Example script |
full.php | Example | Example script |
headers.php | Example | Example script |
https.php | Example | Example script |
jsonObj-multiline.php | Example | Example script |
jsonObj-null-value.php | Example | Example script |
multipart-data.php | Example | Example script |
multipart-file.php | Example | Example script |
multipart-form-data-no-params.php | Example | Example script |
multipart-form-data.php | Example | Example script |
query.php | Example | Example script |
short.php | Example | Example script |
text-plain.php | Example | Example script |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.