Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/minicli/curly
Simple Curl Client
https://github.com/minicli/curly
crawler curl hacktoberfest php
Last synced: 21 days ago
JSON representation
Simple Curl Client
- Host: GitHub
- URL: https://github.com/minicli/curly
- Owner: minicli
- License: mit
- Created: 2020-02-22T06:29:21.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-01T01:56:49.000Z (about 1 month ago)
- Last Synced: 2024-12-07T17:05:20.679Z (about 1 month ago)
- Topics: crawler, curl, hacktoberfest, php
- Language: PHP
- Homepage: https://docs.minicli.dev
- Size: 63.5 KB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# curly
A tiny experimental curl client built for Minicli (but can be also used standalone).## Requirements
Requires `curl` and `php-curl`.
## Installation
To include Curly in your app, first require the dependency with Composer:
```shell
composer require minicli/curly
```## Usage
Use the `Minicli/Curl/Client` class to make GET and POST requests using the `get()` and `post()` methods, respectively.
This example queries the DEV API and gets the latest posts from a user:
```php
$crawler = new Client();$articles_response = $crawler->get('https://dev.to/api/articles?username=erikaheidi');
if ($articles_response['code'] !== 200) {
$app->getPrinter->error('Error while contacting the dev.to API.');
return 1;
}$articles = json_decode($articles_response['body'], true);
print_r($articles);
```The following single-command Minicli application will fetch a user's latest stats from DEV.to using Curly (this requires `minicli/minicli`):
```php
#!/usr/bin/env php
true,
'theme' => '\Unicorn'
]);$app->registerCommand('devto', function () use ($app) {
$app->getPrinter()->display('Fetching from DEV...');
$crawler = new Client();$articles_response = $crawler->get('https://dev.to/api/articles?username=DEVUSERNAME');
if ($articles_response['code'] !== 200) {
$app->getPrinter->error('Error while contacting the dev.to API.');
return 1;
}$articles = json_decode($articles_response['body'], true);
$table[] = ['Title', 'Reactions'];
foreach($articles as $article) {
$table[] = [$article['title'], $article['positive_reactions_count']];
}
$app->getPrinter()->printTable($table);
return 0;
});try {
$app->runCommand($argv);
} catch (CommandNotFoundException $notFoundException) {
$app->getPrinter()->error("Command Not Found.");
return 1;
}return 0;
```