PHPackages                             czim/laravel-service - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. czim/laravel-service

ActiveLibrary[HTTP &amp; Networking](/categories/http)

czim/laravel-service
====================

Basic webservice framework for Laravel.

3.1.0(1y ago)426.9k—0%3[3 issues](https://github.com/czim/laravel-service/issues)[1 PRs](https://github.com/czim/laravel-service/pulls)1MITPHPPHP ^8.1

Since Nov 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/czim/laravel-service)[ Packagist](https://packagist.org/packages/czim/laravel-service)[ Docs](https://github.com/czim/laravel-service)[ RSS](/packages/czim-laravel-service/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (49)Used By (1)

Laravel Service
===============

[](#laravel-service)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9c06c58f43ffa9653e1ce3c27a3ae8f6b40500bde2155a9ddc0c3010473fe770/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f637a696d2f6c61726176656c2d736572766963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/czim/laravel-service)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/80464deac546c604748cac93fbdff0bb2c9e0968360aa0d985aa40e791e3a4e9/68747470733a2f2f7472617669732d63692e6f72672f637a696d2f6c61726176656c2d736572766963652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/czim/laravel-service)[![Latest Stable Version](https://camo.githubusercontent.com/462357e198a8095bbaec01caba0bfced3cc3f61cf2df3a015af42ddb1b3f38fa/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f637a696d2f6c61726176656c2d736572766963652e737667)](https://packagist.org/packages/czim/laravel-service)[![SensioLabsInsight](https://camo.githubusercontent.com/98378c2727fe45b98f6b7568b0309f7b3e7847e11982562abb4de1ed4d7dfe83/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f62393136643337322d366536392d343137392d396537362d3531336631656364613965642f6d696e692e706e67)](https://insight.sensiolabs.com/projects/b916d372-6e69-4179-9e76-513f1ecda9ed)

Basic framework for making standardized but flexible webservice classes.

Version Compatibility
---------------------

[](#version-compatibility)

LaravelPHPPackage5 - 85 - 70.97 - 87.2+1.097.2+1.198.02.09 - 118.13.1Install
-------

[](#install)

Via Composer

```
$ composer require czim/laravel-service
```

Unless you're using auto-discovery, add this line of code to the providers array located in your `config/app.php` file:

```
    \Czim\Service\Providers\ServiceServiceProvider::class,
```

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

[](#requirements)

To use the `SshFileService`, you will require the `libssh2` PHP extension.

Usage
-----

[](#usage)

### Services

[](#services)

The basic approach to using a Service in three steps:

1. Instantiate a Service
    - passing in the defaults (*optional*)
    - passing in an interpreter instance (*optional*)
2. Perform a `call()` on the service instance

For a simple SOAP service, this might be as follows:

```
    // Set up defaults
    $defaults = new \Czim\Service\Requests\ServiceSoapRequestDefaults();

    $defaults->setLocation('http://www.webservicex.net/globalweather.asmx?WSDL')
             ->setOptions([
                 'trace'      => true,
                 'exceptions' => true,
                 'features'   => SOAP_SINGLE_ELEMENT_ARRAYS,
             ]);

    // Instantiate service, with a to-array interpreter
    $service = new SoapService(
        $defaults,
        new \Czim\Service\Interpreters\BasicSoapXmlAsArrayInterpreter()
    );

    // Prepare a specific request
    $request = new ServiceSoapRequest();

    $request->setBody([
        'CityName'    => 'Tokyo',
        'CountryName' => 'Japan',
    ]);

    // Perform the call, which will return a ServiceReponse object
    $response = $service->call('GetWeather', $request);
```

#### Available Services

[](#available-services)

- `RestService`: for HTTP REST requests, requires a `ServiceRestRequest` object for defaults/requests.
    - See the section about RestServices below.
- `RestCurlService`: same as above, but uses cURL directly instead of guzzle
- `SoapService`: for SOAP requests, requires a `ServiceSoapRequest` object for defaults/requests.
    - See the note about BeSimple below.
- `FileService`: for retrieving the contents of a single file, requires a `ServiceSshRequest` object for defaults/requests.
- `MultiFileService`: for retrieving the contents of multiple files and merging their interpretations, requires a `ServiceSshRequest` object for defaults/requests.
- `SshFileService`: like the MultiFileService, but retrieves files by logging into an SSH server. See requirements above.

See this [list of examples](EXAMPLES.md) for more information.

#### RestServices and HTTP methods

[](#restservices-and-http-methods)

One thing to look out for is a potential confusion over the 'method' when using the `RestService`. The `$method` parameter in the service's `call()` does **not** refer to the HTTP Method (`GET`, `POST`, etc). For cross-services compatibility purposes it is used to set the URI path instead, since that best corresponds to the 'method' for SOAP calls. The HTTP Method is to be separately set on the service before making the call, with `setHttpMethod()`.

So making a `DELETE` call to `/comments/13` may be set up as follows:

```
    // Set up the default and base URI for the service
    $defaults = new \Czim\Services\Requests\ServiceRestRequestDefaults();
    $defaults->setLocation('http://base.service.url.com/v1');
    $defaults->setHttpMethod($service::METHOD_DELETE);

    // Instantiate a new service with the defaults
    $service = new \Czim\Service\Services\RestService($defaults);

    // Perform a call to delete comment 13
    $result = $service->call('comments/13');
```

If not set, the default HTTP method is `POST`.

Alternatively, the HTTP method may be configured per-call without affecting the default, by setting it in a `ServiceRequest` parameter:

```
    // Set up the default and base URI for the service
    $defaults = new \Czim\Services\Requests\ServiceRestRequestDefaults();
    $defaults->setLocation('http://base.service.url.com/v1');

    // Instantiate a new service with the defaults
    $service = new \Czim\Service\Services\RestService($defaults);

    // Create a request object with an HTTP method
    $request = new \Czim\Service\Requests\ServiceRestRequest();
    $request->setHttpMethod($service::METHOD_DELETE);

    // Perform a call to delete comment 13
    $result = $service->call('comments/13', $request);
```

The order of precedence is:

1. HTTP method set in request for call
2. HTTP method set in default request for service
3. HTTP method defined in service directly

### Interpreters

[](#interpreters)

Services always return a `ServiceResponse` for each call. The content of the response (mainly the data accessible through `getData()`, but also its other properties) is determined by the `ServiceInterpreter` instance set for the service. ServiceInterpreters are responsible for interpreting and converting the raw data retrieved to whatever (standardized) format and response content you prefer.

Standard available interpreters:

- `BasicDefaultInterpreter`: sets up response, but does not manipulate the raw data in any way
- `BasicJsonInterpreter`: converts a string with raw JSON to an object or associative array
- `BasicQueryStringInterpreter`: converts a query string to an object or array
- `BasicRawXmlInterpreter`: converts a string with raw XML to SimpleXML objects
- `BasicRawXmlAsArrayInterpreter`: same, but converts to an associative array
- `BasicSoapXmlInterpreter`: makes response for SimpleXML object returned by a SoapClient
- `BasicSoapXmlAsArrayInterpreter`: same, but converts to an associative array

It is recommended to extend these or roll your own interpreter for complex services. I often build interpreters that use [`czim/laravel-dataobject`](https://github.com/czim/laravel-dataobject) to convert raw data into validatable, specific data objects. See the [AbstractServiceInterpreter source](https://github.com/czim/laravel-service/blob/master/src/Interpreters/AbstractInterpreter.php) for hints and useful methods.

#### Interpreter Decorators

[](#interpreter-decorators)

Some decorators for interpreters are provided:

- `FixXmlNamespacesDecorator`: rewrites relative path namespaces to absolute in raw XML, since some XML may be uninterpretable otherwise (hacky).
- `RemoveXmlNamespacesDecorator`: removes XML namespaces from raw XML entirely (hacky).

They follow the standard decorator pattern for interpreters, so they may be used as follows:

```
    // Decorate a raw XML interpreter with a namespace removal decorator
    $interpreter = new \Czim\Service\Interpreters\Decorators\RemoveXmlNamespacesDecorator(
        new \Czim\Service\Interpreters\Decorators\BasicRawXmlInterpreter()
    );

    // Inject the interpreter into a new service
    $service = new \Czim\Service\Services\FileService(null, $interpreter);
```

The `AbstractValidationPreDecorator` may be extended to easily set up validation of raw data before the decorated interpreter does its business. Likewise the `AbstractValidationPostDecorator` may be extended to validate the `ServiceResponse` object returned *after* the interpreter has treated the response.

### Service Collection

[](#service-collection)

By way of wrapping multiple services, this package offers a `ServiceCollection`. This is a simple extension of the `Illuminate\Support\Collection`, which may only be used to store `ServiceInterface` objects.

You can set one up just as you would a normal Collection:

```
    $services = new \Czim\Service\Collections\ServiceCollection();

    // Adding services
    $services->put('service name', $service);

    // Performing calls on a service
    $service->get('service name')
            ->call('someMethod', [ 'param' => 'value' ]);
```

Note that calling `get()` on the collection for a non-existant service will throw an exception; as will trying to store something other than a `ServiceInterface` in it.

Notes
-----

[](#notes)

### BeSimple SoapClient

[](#besimple-soapclient)

The `BeSimpleSoapService` service class is set up to use the BeSimple SoapClient.

The only thing required to use it is to include the package:

```
composer require "besimple/soap-client"

```

### DOMDocument parsing as an alternative to SimpleXml

[](#domdocument-parsing-as-an-alternative-to-simplexml)

When using the `DomDocumentBasedXmlParser`, note that this will not return a *SimpleXml*-type object, but a `DOMElement`. To sensibly use this, convert it to an array using the `DomObjectToArrayConverter`. This means that when rebinding or injecting one of these, treat them as a pair.

Note that the DOMDocument method is slower and uses significantly more memory. If you have no specific reason to use this, stick to the default.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Coen Zimmerman](https://github.com/czim)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance25

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.4% 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 ~74 days

Recently: every ~238 days

Total

46

Last Release

506d ago

Major Versions

0.9.36 → 1.0.02021-03-31

1.1.0 → 2.0.02022-05-18

2.0.0 → 3.0.02022-10-07

PHP version history (4 changes)0.9.0PHP &gt;=5.4.0

1.0.0PHP &gt;=7.2

2.0.0PHP ^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1657b09521b6030fe32d864a493ded8b1dbbdf737ef3772135dfc123cea34767?d=identicon)[czim](/maintainers/czim)

---

Top Contributors

[![czim](https://avatars.githubusercontent.com/u/11831617?v=4)](https://github.com/czim "czim (17 commits)")[![wimski](https://avatars.githubusercontent.com/u/12373573?v=4)](https://github.com/wimski "wimski (1 commits)")

---

Tags

connectorlaravelwebservicerestservicesoapwebservice

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/czim-laravel-service/health.svg)

```
[![Health](https://phpackages.com/badges/czim-laravel-service/health.svg)](https://phpackages.com/packages/czim-laravel-service)
```

###  Alternatives

[srmklive/paypal

Laravel plugin For Processing Payments Through Paypal Express Checkout. Can Be Used Independently With Other Applications.

1.1k3.8M26](/packages/srmklive-paypal)[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[jlevers/selling-partner-api

PHP client for Amazon's Selling Partner API

4295.2M1](/packages/jlevers-selling-partner-api)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.3M14](/packages/xeroapi-xero-php-oauth2)[cundd/rest

REST API for TYPO3 CMS

78120.0k1](/packages/cundd-rest)

PHPackages © 2026

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