Download the PHP package virge/api without Composer

On this page you can find all versions of the php package virge/api. 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 api

Virge::Api

Virge::Api allows the simple creation of API endpoints.

Virge::Api allows defining get/post/put/delete methods, as well as chaining API authentication methods by defining custom verifiers.

Getting Started

To use Virge::Api you should start with a default Virge::Project

This will create an empty Virge::Reactor, and create the skeleton required to setup the Api.

The entire directory needs to exist on your webserver, but the entry directory should be the ./public directory, this can be symlinked:

This can also be done using docker:

Once the container is up, you'll need to run the symlink command like above

Virge::Project also requires rewrites, for apache you can set that up by creating myproject.conf in /etc/httpd/conf.d/

Restarting the docker container or apache will then allow you to visit localhost:3000 in your browser. You will get a 500 error, a blank white page, or a 404 page depending on configuration. This is because there is no routing or routes setup.

Hello Api

We need to include Virge::Api as a capsule, and add the package to our project:

To create our first API route, we need to create our First Capsule. A Capsule is registered with the Reactor and will automatically load configuration files for us, loading services, controllers, and api definition files.

Under the src directory we can create a MyProject directory We will need to create MyProjectCapsule.php under this directory:

Now we need to add our Capsule to app/Reactor.php, add both the MyProject\MyProjectCapsule() as well as the Virge\Api\Capsule()

While in this file, we can also define what API version(s) are active. after our parent::registerCapsules call, let's enable version 1 of our Api:

We also need to tell composer to automatically load our capsule, update bootstrap.php to add our namespace:

Now we can register our API Method, creating the file src/MyProject/resources/config/api.php

Visiting http://localhost:3000/api/v/1/hello should now return a json response with "world"

Api's can also call controller functions, and the methods are passed in the Virge::Router Request object, allowing you to get the JSON request body, GET and POST Fields, as well as URL parameters.

Api Verification

You can define custom API verifiers, which are simply callback functions that return true or false to allow access For example, to update our hello API endpoint to require an api key, we can add a verifier: In config/api.php

Visting http://localhost:3000/api/v/1/hello in your browser will now return a non successful response, but adding in the apiKey: http://localhost:3000/api/v/1/hello?apiKey=123 Will allow you to visit the page.

A method can have as many verifiers as you want, and ALL verifiers must return true for the function to be called and the method to be successful.

Api Parameters

Api method names can also contain URL Parameters, these parameters are accessed via the request object:

Visiting http://localhost:3000/api/v/1/hello/bob will now return a JSON body with "Hello: bob"


All versions of api with dependencies

PHP Build Version
Package Version
Requires virge/core Version ~2.0.0
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 virge/api contains the following files

Loading the files please wait ....