Download the PHP package pilskalns/f3-wcurl without Composer

On this page you can find all versions of the php package pilskalns/f3-wcurl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package f3-wcurl

This plugin at the moment is unmaintained and almost certainly will stay so.

The projects from me that depended on this have either become obsolete or found other forms and shapes i.e. as Lambda functions.

Thanks F3 developers for the framework, it was fun time learning it and building automation stuff that was running for years without need to touch. I will archive this repo once the last project running will be taken offline. Please feel free to fork.

F3-wcurl

master dev
Master Status Dev Status

A Fat Free Framework plugin: Bridge between your code and external REST API. F3-wcurl acts as a logical abstraction layer for cURL, which handles authentication and sucess response caching.

F3 built-in Web plugin is great and easy to handle individual HTTP requests. F3-wcurl builds implementation of the whole remote API inside your code.

Preface

Over the time I've had need to quickly build tools and scripts that had one essential, but repetetive task with them: to handle cURL requests, settings, objects, responses etc. In the end, I kept copying the same functions, modifying them and debbuging the same issues why something isn't working written months ago.

Even though you have great control over and access to cURL options, F3-wcurl does not force you to do so. It lets focus on the request itself, what does it change and receive in return. As a plugin for F3 ecosystem, it naturally got few cool dependencies - Prefab, Cache and Web (not for cURL requests themselves).

Initiate the class

F3 class is built from associative array of relevant settings. Array can be passed from either code directly, or either from INI file (imported to F3 before building F3-wcurl) and stored in the F3 hive.

F3-wcurl uses F3's Prefab and Cache, which allows same wcurl object to be called anywhere from the code and quick response turnover.

On default, F3-wcurl will search for wcurl key in F3 hive, but INI can conviniently hold settings for multiple different REST API implementations.


Options array

This fairly simple array structure defines inner workings of wcurl:

name type default description
root string null Remote API root, which is used to build request URI.
cb_login string null Set callback function from your code, which can perform authentication, which should be valid callback for call_user_func()
ttl integer 60 Seconds, how long to cache GET responses
headers array [ ] cURL valid array of strings ["Header: value", "Another-Header: Value"]
useragent string F3-wcurl version Useragent string
basicauth string null Send Basic Auth headers, use in format username:password
queryToken string null Append each request with URL token
encodeJSON boolean true Weather serialize POST body as JSON, setting false will send body as regular HTML form
curlopt array [ ] RAW cURL settings RAW cURL settings array for outright control, with key => val where key can be either constant or either string name of it
rests array [ ] key => val table for URL building helpers (see Examples section)

updating options

setOptions

To set any option from table above, pass key => val array with one or more options.

Only options you pass will be updated, everything else will stay in previous/default state.

clearOptions

To clear one or more options, pass name or array list of keys you wish to reset to defaults:

getOptions

To get full array of options that represents current state of wcurl class:

Returned multi-dimension array should be compatible to create exactly the same class as the one extracted from.

getStats

Will return statistics how many requests are executed since class is created, what/how many http responses received and how many served from cache.


HTTP functions

Currently supported functions are GET, POST, PUT, PATCH and DELETE. Though will be adding more as I come over the need to implement them.

GET

I memorize arguments like this.

UFO:

POST

UFBO - Url, Fill, Body, Options

PUT

UFBO - Url, Fill, Body, Options

PATCH

UFBO - Url, Fill, Body, Options

DELETE

UFBO - Url, Fill, Body, Options


Using table of rests (REST pointS)

Rests table serves two equally important purposes:

  1. To shorthand API paths avoiding typos of long strings
  2. To fill in parts of those strings to build dynamic API call paths

When constructing long remote URL paths, it's easier to remember them by short keywords, especially if they are called from multiple places. Like allmembers instead of /lists/members/all/pages. Sometimes these contain also unique parameters, which needs to be filled in per each request. This concept is one of main reasons why this plugin exists.

Keep on reading.

Set named paths

The best ways is to store remote paths in the .ini configuration. URL variables for fill are wrapped in two % from both sides.

TODO: Make this wrap character configurable.

or pass simple key => value array on the fly - it will be merged over with previous configuration

Use named paths

To use named route, pass it's name instead of full path

This will resolve to /lists/members/all/pages

Use named paths with variables

This will resolve to /lists/members/abc123ID/pages

Or in the POST request we know that have to pass following UFBO parameters


Using INI configuration

If you put all configuration in your main ini file, class can be initialized only on first required use of it. I.e. when your code decides to send get(). At that moment, if class is not registered in Prefab, it will be built from INI config exactly as needed.

For full list of options refer to Options Array table few scrolls above.


Examples

cb_login

If any request results in HTTP 401 or 403 code, wcurl calls Login callback function and then repeats original request. If again there is error, it is returned to original function result. wcurl stores cookies in temporary file unique to API root. This cookie file is included in every request.

Callback must return true, if login success, otherwise it would fail to auto-repeat request after auth success.

N!B! If login doesn't works, but still return true, it can cause request->login->request->login... infinitive loop

Login function example

Using with multiple API's

When calling \wcurl::instance() it is returned like singleton class, thus in any place in code, same object is used. To force fresh instance from class, use something like

And then $apiTwo can be stored in F3 hive.

There's a lot to improve, but currently will be making features I need. If something not possible for your use case, submit an issue or even PR. Thanks to F3 developers for this wonderful framework. If you are looking for something as F3-wcurl, but don't use it, then think twice - Why you are not using F3 yet?


All versions of f3-wcurl with dependencies

PHP Build Version
Package Version
Requires bcosca/fatfree Version ^3.6
ext-curl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pilskalns/f3-wcurl contains the following files

Loading the files please wait ....