iPrice RESTful API Generator
Generate secure RESTful APIs for your models.
Features
JWT-Based Authentication
- Choose to secure your resource endpoints with JWT-based authentication or not.
Resource Relationship Eager-loading
- Set which relationships should always be eager-loaded on
GET
requests.
GET
- Get a collection of resources.
- Get a single resource.
- Filter by column using query parameters or route parameters.
- Paginate using the
page
query parameter with configurablelimit
query parameter.
POST
- Create a resource.
PUT
- Update a resource.
DELETE
- Delete a resource.
Creating/editing a resource endpoint
The resource form has the following fields:
- Base Endpoint (required): the base url of the endpoint you want to create. Examples are
api/v1/blogs
,api/v1/{category}/blogs
. You can have a route parameter as in the example ({category}
) but make sure the parameter name is an actual field in your resource table and resource name (blogs
) is placed at the end. - Model Class (required): the Eloquent model class you want to expose in the API as a resource.
- Eager Load Relationships: the relationships specified in your Eloquent model class you want to eager-load on every
GET
request. Visit the October CMS Database Relationships on how to set-up relationships. - Require Authentication: check this if you want to protect your resource API with JWT-based authentication.
Using your resource API
GET
requests
To request a collection, do something like the following:
# Basic collection GET example.com/api/v1/blogs # Filtered collection. # note: you can use any fields from the resource as filter # and you can use as many filters as you want. GET example.com/api/v1/blogs/?category=tech
By default, the API will return the first 10 results. If you want to get the next batch or return more than the default limit, you can use the page
and/or limit
query parameters like the following:
# Get the first 20 results. GET example.com/api/v1/blogs/?limit=20 # Get the next 20 results. GET example.com/api/v1/blogs/?page=2&limit=20 # You can use the `page` and `limit` query parameters # along with any filters you need. # Filter by category and get the results from page 2. GET example.com/api/v1/blogs/?category=tech&page=2
If you specified a route parameter in your endpoint, eg: api/v1/{category}/blogs
, you need to specify a value in place of the route parameter:
GET example.com/api/v1/tech/blogs
You can still use pagination and filters along with route parameters.
To get a single resource, specify the resource ID after the base endpoint:
GET example.com/api/v1/blogs/1 GET example.com/api/v1/tech/blogs/1
PUT
requests
You can update a resource by doing a PUT
request to a specific resource with a payload:
PUT example.com/api/v1/blogs/1 -H 'content-type:appilcation/json' -d '{"title":"Updated blog title"}'
DELETE
requests
You can delete a resource by doing a DELETE
request to a specific resource:
DELETE example.com/api/v1/blogs/1
Authentication
If you chose to protect your API endpoints with authentication, you need to acquire a token by logging in and use that token on every API request you make.
To manage API users, please refer to RainLab User plugin.
To log in, make a POST
request to the api/auth/login
endpoint with a login
and password
payload:
# Acquire a token (login) POST example.com/api/auth/login -H 'content-type:application/json' -d '{"login":"user@example.com","password":"password123"}'
If successful, it will return something like the following:
{ "token": "some.jw.token", ... }
Use the value of the token
field as a bearer token in the header or as a token
query parameter:
# As a header GET example.com/api/v1/blogs -H 'authorization: bearer some.jw.token' # As a query parameter GET example.com/api/v1/blogs/?token=some.jw.token
-
tetraneon
Found the plugin useful on 8 Mar, 2022
Some bugs have been solved. See at : https://github.com/iPriceGroup/ocapiplugin/issues
-
DLEEE
Found the plugin not useful on 28 Jan, 2021
Hello, component is not install, error "Authority to provide plugin "RLuders.JWTAuth" could not be found"
-
ErmilovNikita
Found the plugin not useful on 22 Jan, 2021
Hey. When installing the module, I get the error "Undefined index: IPriceGroup\OcApiPlugin\Models\Resource" on line 242 of /var/www/puparas.ru/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
-
ioCare
Found the plugin useful on 5 Aug, 2019
Hi, suggest you to make available the github repo so that others can contribute. Also add ->orderBy('created_at', 'desc'); to initializeQueryBuilder so that data rows obtained does not shift as on change updated at time changes and that's default criteria for order by.
-
CanThis
Found the plugin useful on 4 Jun, 2019
First, thanks for such a great and useful plugin! Works very well, but it would be great to have ability to provide multiple middlewares per route (backend settings page with frequently used middleware list maybe?) and ability to enable/disable particular HTTP methods such as GET, POST, PUT, DELETE
Thoughts?
-
1.2.0 |
Remove `relationship` key from eager_load Feb 14, 2020 |
---|---|
1.0.7 |
Fix issue where custom controllers get overwritten with default controller after saving a resource Nov 13, 2019 |
1.0.6 |
Update API to support sorting Nov 13, 2019 |
1.0.5 |
Update API to support advanced filter Nov 13, 2019 |
1.1.1 |
Fix issue with OctoberCMS not installing plugin composer dependencies Oct 21, 2019 |
1.1.0 |
Create ocapiplugin:routes:sync command to sync routes via CLI for CD Oct 21, 2019 |
1.0.4 |
Add custom filters property to be exclude in actual filters Oct 07, 2019 |
1.0.3 |
Use plugin icon in navigation Apr 23, 2019 |
1.0.2 |
Register Manage APIs permission Apr 23, 2019 |
1.0.1 |
Make base_endpoint unique and remove soft delete Apr 16, 2019 |
1.0.0 |
Initialize plugin Apr 12, 2019 |