Download the PHP package eftec/apiassembler without Composer

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

ApiAssembler

If you have a database up and running, then you can create an API in less than 3 minutes or less. This library creates a boilerplate of an API Rest server based in the tables of a database. Unlikely other libraries, this library generates native code, so it allows any customization.

It is an alternative to Firebase, while it is less friendly, but it is also more flexible (and you can use your current data).

This library is compatible with the next databases (using the component PDO):

Packagist Total Downloads [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

Features

Ideology of the architecture.

This library is not RESTFUL by design, however you can customize and use as RESTFUL.

Why? While RESTFUL could be simple, but it is also limited. This library allows to create a dozen of actions for API and those actions are not allowed in a simple RESTFUL server. I.e. you can read information using any verb, including POST because why not?.

Verbs allowed: GET, POST, PUT and DELETE.

Also, this library is by design static, any action is aimed to do a simple task instead of have a API methods that does many operations at the same time. That is different to GraphQL and other libraries, where the client could customize its queries. The reason behind it is security and performance.

Let's say we have the new path to list all the products.

url: domain.dom/api/Product/listall (GET/POST/PUT or DELETE)

It will be separated in:

It could call the next method:

But what if we want to call it only for a specific verb (POST)

Now, let's say we want to list products of a "category" and only for GET

url: domain.dom/api/Product/listByCategory/200 (GET)

Getting started

The code of the controller and repository class could be generated using a CLI command:

1) Running the code

However, for starter, just use this line: (since we don't have a configuration yet)

And the CLI will ask several questions such as connection to the database, etc.

If the information is correct, then it will show an [OK] message. Otherwise, you can try it again.

Once connected, it will show the next menu:

2) Scan (step required)

Scan will read the database for changes, and it will detect if there is a new tables/columns or if some tables/columns must be removed.

3) Folder (step required)

Now try the next option folder where you can set where the repository files will be generated. You also set the postfix of the new repository classes (usually it is called Repo)

You also must set the namespace of those clases. The namespace depends in your folder structure and composer's autocomplete configuration.

In this case, the root folder is located at d:\www\currentproject\ApiAssembler and composer.json contains the next line:

4) Apifolder (step required)

It is similar to folder but it is used to determine where the API controllers will be located and what will be the namespace.

5) Router (Required)

In this menu, you can generate the router.php, router_auth.php and the .htaccess file.

6) APIMethod (Required)

You can add or remove methods of the API Controller class.

You can add or remove a method for every class or for all classes at the same time.

7) Generateapi (Required)

And when you have all the information, then you can generate the repository and API controller files.

In the last example, we classes were generated but there is not method assigned. Otherwise, it will build the code.

8) Saveapi (Recommended)

Finally, you can save your configuration, so you can run it once.

You can save your configuration and a script file to recall the process again.

In the last example, you can continue the configuration running one the next lines

Why the configuration is saved as a PHP file? (example.config.php)

It is for safety measures. That file is not visible via Internet, even if it is keep in the web folder. It is because it contains a line that avoid the execution of the code.

9) Running the code

You can run the code by opening the url where you create your files. If you are in the developer machine, then it will show the next screen. If you click on those options, then you can call your code if the function allows the method GET and it doesn't require any other value.

10) Rename using Detail (optional)

While the previous code could work but there are some naming problems. Invoices table is named "Invoic" instead of "Invoice". Also Invoicedetails table ls called "Invoicedetail" instead of "InvoiceDetail".

So let's rename the column:

Then, you can re-build the router (menu "router") and generate the files again (menu "generateapi")

Structure of the project

The project is quite minimalist, it consists of 3 folders

📁 root folder

​ 📁 repository folder

​ 📁 api controller folder

In the root folder there are 3 files

  1. Selects the type of the database, mysql, sqlsrv (mssql server) or oci (Oracle)
  2. It selects the server machine. It depends on the type of database
    1. mysql: the IP of the server
    2. sqlsrv: the IP / instance or name machine / instance
    3. oci: It could be the tsname or the ez-config
  3. The user name of the database. In OCI, it is also the schema.
  4. The password of the database.
  5. The database to connect.
  6. The base namespace, example: "\namespace1\namespace2"
  7. The folder (relative to the current path) of where the repository classes will be generated.
    1. If the folder does not exist, then it will be created.
  8. The folder (relative to the current path) of where the apiclasses will be generated.
    1. If the folder does not exist, then it will be created.
  9. You can select the table to process or remove. All tables marked with "*" are selected
  10. You can decide to rename a class.
    1. By default, the name of the classes are generated using the name of the tables in singular.
  11. You can add a method to a class
    1. Inside this method, you can add one new method for a class. A method consists of the type of method, name and HTTP verb. Check the list of methods for more information.
  12. Yes if you want to generate the route file (route.php). If the file exists and we select to "no to override", then the file is not generated and: you can delete it manually or force to override it.
  13. You can select if the current machine is the developer or production machine. Router.php by default contains two ambiances, developer and product. The code determines automatically the current ambiance using the name of the machine.
  14. You can set the name of the machine or left it automatically.
  15. You can set the base web URL (developer). The base web is the web that it must show it in the current folder.
    1. For example, lets say you are working in the new folder /var/www/domain.dom/example/folder or in the folder c:\www\example\folder, then if the root url folder (http://localhost) points to /var/www/domain.dom or c:\www, then your base web URL must be http://localhost/example/folder (without the trailing "/")
  16. You can set the base web URL (production). The base web is the web that it must show it in the current folder.
  17. You can set the API folder.
    1. The end url is composed by BASE WEB URL / API FOLDER / CONTROLLER / ACTION / ID / IDPARENT
    2. Example: "http://localhost/api/Product/list/20" (in this example, idparent is not set)
  18. You can select if you want to use or not cache
    1. You can select the type of cache (redis, apcu or memcached)
    2. You can select the IP of the cache server (usually 127.0.0.1)
    3. You can select the port of the cache server
    4. You can select the schema (or folder) of the cache
    5. You can select the user of the cache server, if any (by default, redis, apcu and memcached does not use user or password)
    6. You can select the password of the cache server, if any
  19. If you mark yes, the every file is override. Otherwise, the code only generates files that don't exist.
  20. Finally, you can save all the user input values in a file.
    1. Later, you can recover the configuration as php ApiAssembler.php -create -file file.json

List of methods

It is the list of template of methods allowed to the creation of a new method.

methods action default input values default output
insert insert a new record. Values are received by the body (json) return the last identity (if any) or the primary key
update update a new record. Values are passed by the POST body (json) Values are received by the body (json)
delete delete a new record by using the id. V Values are received by the body (json)
get get a single row using the primary key domain/controller/action/PRIMARYKEY Returns a json with the row or null if none
count count the number of records (all rows) Returns a json with the number of rows
listall list all the records. You should not use it in a huge table, use instead listpaged. Returns a json with the rows or null if none
listpaged list the record paged, order and sorted. The URL must be in the form of domain/controller/action?page=numpage&order=column&orderdir=desc, where numpage must starts with 1. Returns a json with the rows or null if none
listfilter list the records that matches a condition Returns a json with the rows or null if none
listraw runs a raw (sql native query) query Returns a json with the result or null if none
alias creates an alias of a method (a method that calls other method).
For example, an empty alias that calls the method listall
domain/controller/ -> domain/controller/listall It calls other methods
empty empty method, you can edit it on your own.

Verbs:

verb description
GET HTTP GET. You can't get the body.
POST HTTP POST
PUT HTTP PUT
DELETE HTTP GET
ALL All verbs. In case of conflict with other methods, this method have the lower priority.

Database Methods

This library uses EFTEC/PDOOne to do the connection to the database.

There are many other methods (including DDL methods) but they are the basic ones.

Cache

It also allows to cache the results as follows:

Reading information

If you want to read user input, then, you can still use $_GET and $_POST values but you also could read values from the Router

Reading the body:

Reading a header

Reading a URL parameter

Reading a post parameter

Reading the post if not the URL parameter

Changelog

Licence

Copyright: Jorge Castro Castillo - Eftec Chile (2022-203)

Dual License, GPL-v3 and Commercial. See license file for more information

In short (not legal advice):

"You may copy, distribute and modify the software as long as you track changes/dates in source files. Any modifications to or software including (via compiler) GPL-licensed code must also be made available under the GPL along with build & install instructions. If you don't want to use GPL license, then you can opt for a commercial license."


All versions of apiassembler with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.5
eftec/clione Version ^1.22.2
eftec/pdoone Version ^3.16
eftec/validationone Version ^2.7
eftec/routeone Version ^1.27
ext-json Version *
eftec/cacheone Version ^2.13
eftec/authone Version ^1.4
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 eftec/apiassembler contains the following files

Loading the files please wait ....