Download the PHP package andyabih/laravel-fake-api without Composer

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

Laravel Fake API

Create placeholder API endpoints from a simple PHP array.

LFA utilizes Faker for dummy data.

Inspired by JSON Server.

Installation

To install LFA, run the following composer command:

Next, publish the config file to fill in your endpoints & responses:

Configuration

Below is a sample laravel-fake-api.php config file:

Base endpoint

LFA registers the /api/fake/ prefix for all endpoints, you can change that by changing the base_endpoint entry in the configuration file.

Endpoints

Inside the endpoints array, you can create all your different endpoints. The example above contains two: /posts and /categories (/api/fake/posts for full).

Fields

For each endpoint, you can then specify all the fields you want the response to contain. We've defined 5 here: id, title, slug, text, and category. The values for these fields are Faker methods. Make sure you snake case them (ie: randomDigit becomes random_digit), and any additional argument you want to pass should be separated with a pipe; so "text" => 'paragraph|2' translates to paragraph(2).

In case you want to show a foreign entity inside the endpoint response, you can prefix it with an underscore. A plural key will return an array of multiple entities, and a singular one would return only one (ie: "categories" => "_categories" will return an array of categories, but "category" => "_category" will only return a single entry).

If you are requesting multiple relationship entities, you can also pass in an optional argument specifying the amount of results you want, so you can do something like "categories" => "_categories|5" which will return 5 categories.

Endpoint settings

A reserved _setting key is used to specify any additional settings to the endpoint. Currently, only 3 settings are available: identifiable, paginate, and auth.

Identifiable

The identifiable option will determine what column name is used to identify specific entries. The default value for the identifiable setting is id, meaning a GET call to /api/fake/categories/1 will check against the id field. In the above example, posts are identified by their slug, so you will need to access them using something like /api/fake/posts/post-slug-here.

Paginate

Straightforward here. If you are expecting multiple results, you can paginate the response by enabling the paginate option (which is by default false), and specify the amount of entries you want per page (so 5 in the example).

Auth

LFA also offers a 'fake' authentication layer. If enabled (it's false by default), you will receive a 401 unauthorized error if you do not call the endpoint with an Authorization header. No further checks are done on the token, it just checks if the header exists.

Filters

_count

You can pass in the query parameter _count to specify the number of results you want. Calling /api/fake/categories?_count=5 will return 5 categories.

_without

You can use the _without parameter to specify which columns you want to exclude. /api/fake/posts?_without=title will return posts without the title field.

_only

Same logic as _without, but this time you specify which columns you want to include. /api/fake/posts?_only=title will only return the title field for the posts.

_no_relationships

You can specify that you want to ignore all embedded relationships with the _no_relationships parameter. /api/fake/posts?_no_relationships=1 will not return the category entity inside the response.

Column name

You can also pass in a column name with a value to filter by value. /api/fake/posts?slug=slug-1 will only return entries where the slug field is equal to slug-1. Also works with relationships, so you can do something like /api/fake/posts?categories__id=1, the format for this is entityName__fieldName.

Preset responses

LFA checks for a laravel-fake-api.json file in the root of your Laravel project. If available, LFA will combine both the randomized dummy data & the preset responses in your JSON file.

A sample JSON file for the above configuration could be something like:


All versions of laravel-fake-api with dependencies

PHP Build Version
Package Version
No informations.
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 andyabih/laravel-fake-api contains the following files

Loading the files please wait ....