PHPackages                             lonnylot/crud-sugar - 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. lonnylot/crud-sugar

ActiveLibrary[API Development](/categories/api)

lonnylot/crud-sugar
===================

CRUD sugar for REST APIs

4.1.1(4y ago)39.3k[2 PRs](https://github.com/lonnylot/crud-sugar/pulls)MITPHP

Since Dec 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/lonnylot/crud-sugar)[ Packagist](https://packagist.org/packages/lonnylot/crud-sugar)[ RSS](/packages/lonnylot-crud-sugar/feed)WikiDiscussions develop Synced today

READMEChangelog (6)Dependencies (4)Versions (27)Used By (0)

Introduction
============

[](#introduction)

This is meant to be a base for new REST APIs. You can use this to get started so you don't have to worry about the basics (i.e.: setting API keys, making the request).

Composer
--------

[](#composer)

You can install the bindings via Composer. Run the following command:

`composer require lonnylot/crud-sugar`

To use the bindings, use Composer's autoload:

`require_once('vendor/autoload.php');`

Dependencies
------------

[](#dependencies)

The library requires the [GuzzleHTTP](http://docs.guzzlephp.org/en/stable/) library.

Getting Started
---------------

[](#getting-started)

There are three steps to getting endpoints working:

### Setting up your Client

[](#setting-up-your-client)

```
$client = \CrudSugar\Client::getInstance();
$client->setBaseUrl('https://api.telnyx.com/');
$client->setApiKey('secret-key');
```

> *NOTE* See [Creating Instances](#creating-instances)

### Registering your endpoints

[](#registering-your-endpoints)

```
$client->registerEndpointClass(NumberSearch::class);
```

> *NOTE* See [Endpoint Example Class](#endpoint)All endpoints must use `\CrudSugar\Concerns\IsEndpoint`

### Use your endpoint

[](#use-your-endpoint)

```
$response = $client->numberSearch->index();
```

Working With Responses
----------------------

[](#working-with-responses)

All requests return a [Response](src/Response.php) object.

> *NOTE*: Response decorates the [GuzzleHTTP Response](http://docs.guzzlephp.org/en/stable/psr7.html#responses). All methods available on the GuzzleHTTP Response are also available through the returned Response object.

### Response API

[](#response-api)

#### isJson

[](#isjson)

Returns `true` if the `Content-Type` header contains `\json` or `+json`

#### isSuccessful

[](#issuccessful)

Returns `true` if the status code is &gt;= 200 &lt; 300

#### getContent

[](#getcontent)

If `isJson` then returns an associative array. Otherwise returns a string.

### IsEndpoint API

[](#isendpoint-api)

#### setPath(string $path)

[](#setpathstring-path)

Required. The base path to your endpoint. Should not begin or end in a `/`. Should not include any resource specific IDs. Automatically re-builds resource paths.

#### setResources(array $resources)

[](#setresourcesarray-resources)

The list of resources this endpoint has. Defaults to `['index', 'show', 'store', 'update', 'delete']`.

#### setResourcePath(string $resource, string $path)

[](#setresourcepathstring-resource-string-path)

Set the path for a specific resource. Overrides the resource path generated by `setPath`.

#### setResourceMethod(string $resource, string $method)

[](#setresourcemethodstring-resource-string-method)

Set the method for a specific resource.

Advanced
--------

[](#advanced)

### Creating Instances

[](#creating-instances)

You can create and instance by calling `\CrudSugar\Client::getInstance()`, but you can also create named instances by calling `\CrudSugar\Client::getInstance('telnyx')`. If you name your instance then you can get that same instance anywhere in your app.

### Endpoints

[](#endpoints)

All endpoints must use the `\CrudSugar\Concerns\IsEndpoint` trait.

#### Resource Validation

[](#resource-validation)

This package uses the [Laravel Validator](https://laravel.com/docs/6.x/validation).

> *NOTE* The rules requiring a database (Exists, Unique, etc.) are **not** implemented.

To validate a resource you can make a validation function that returns the [rules](https://laravel.com/docs/6.x/validation#available-validation-rules).

##### Endpoint Example

[](#endpoint-example)

```
use CrudSugar\Concerns\IsEndpoint;

class NumberOrder {
  use IsEndpoint;

  public function boot() {
    $this->setResources(['store']);
    $this->setPath('number_orders');
  }

  public function validateIndexRules() {
    return [
      "phone_numbers" => ['required', 'array'],
      "phone_numbers.*.phone_number" => ['required', 'string']
    ];
  }
}
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 97.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Recently: every ~21 days

Total

23

Last Release

1487d ago

Major Versions

1.5.0 → 2.0.02021-02-08

2.1.0 → 3.0.02021-08-16

3.4.0 → 4.0.02022-02-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/64b21af385cbc107515398b5087e1dc0de97c7cfa3a9a02034a46c9b9979a3c2?d=identicon)[lonnylot](/maintainers/lonnylot)

---

Top Contributors

[![lonnylot](https://avatars.githubusercontent.com/u/656791?v=4)](https://github.com/lonnylot "lonnylot (66 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lonnylot-crud-sugar/health.svg)

```
[![Health](https://phpackages.com/badges/lonnylot-crud-sugar/health.svg)](https://phpackages.com/packages/lonnylot-crud-sugar)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
