PHPackages                             craftcms/element-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. craftcms/element-api

ActiveCraft-plugin[API Development](/categories/api)

craftcms/element-api
====================

Create a JSON API for your elements in Craft

4.2.0(1y ago)503701.3k↓15.4%55[3 PRs](https://github.com/craftcms/element-api/pulls)8MITPHPCI passing

Since Aug 19Pushed 1y ago11 watchersCompare

[ Source](https://github.com/craftcms/element-api)[ Packagist](https://packagist.org/packages/craftcms/element-api)[ RSS](/packages/craftcms-element-api/feed)WikiDiscussions 4.x Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (46)Used By (8)

Element API for Craft CMS
=========================

[](#element-api-for-craft-cms)

This plugin makes it easy to create a JSON API for your entries (and other element types) in [Craft CMS](http://buildwithcraft.com).

It’s powered by Phil Sturgeon’s excellent [Fractal](http://fractal.thephpleague.com/) package.

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 4.3.0+ or 5.0.0+.

Installation
------------

[](#installation)

You can install this plugin from the Plugin Store or with Composer.

#### From the Plugin Store

[](#from-the-plugin-store)

Go to the Plugin Store in your project’s Control Panel and search for “Element API”. Then click on the “Install” button in its modal window.

#### With Composer

[](#with-composer)

Open your terminal and run the following commands:

```
# go to the project directory
cd /path/to/my-project.test

# tell Composer to load the plugin
composer require craftcms/element-api

# tell Craft to install the plugin
./craft plugin/install element-api
```

Setup
-----

[](#setup)

To define your API endpoints, create a new `element-api.php` file within your `config/` folder. This file should return an array with an `endpoints` key, which defines your site’s API endpoints.

Within the `endpoints` array, keys are URL patterns, and values are functions that define the endpoint configurations.

```
