Download the PHP package pumasoft/puma-api without Composer

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

PumaAPI

Version PHP License

API Gateway for Puma Services

PumaAPI is a lightweight micro API module designed to parse, validate, and authenticate REST requests based on a simple, file-driven contract architecture. It leverages JWT (JSON Web Token) authentication and provides a clean, declarative way to define your API endpoints through JSON contract files.


Table of Contents


Features


Requirements


Installation

Manual Installation

  1. Clone or download the repository
  2. Include the autoloader or manually require the necessary files

Quick Start


Architecture Overview

PumaAPI follows a contract-first approach where API behavior is defined through JSON manifest files:

Core Components

Component Description
API Main controller that orchestrates the request lifecycle
Request Parses and structures incoming HTTP requests
Contract Loads and validates requests against JSON contracts
Validator Performs field-level validation based on rules
Tokenizer Handles JWT generation, parsing, and verification
Certificate Contains validated request data for controller use
Caller Makes outbound HTTP requests to other services
Rawr Custom exception handler with HTTP response support

Manifest Structure

Directory Layout

The manifest directory follows a RESTful hierarchy:

URL Mapping:

HTTP Request Contract File
GET /auth/login __manifest/get/auth/login.json
POST /users/create __manifest/post/users/create.json
PUT /users/update __manifest/put/users/update.json
DELETE /users/remove __manifest/delete/users/remove.json

Contract File Format

Each JSON contract defines the expected request format and response structure:


Validation Rules

Validation rules are specified using the <<ruleName>> syntax. Available built-in rules:

Rule Description Example
<<notEmptyString>> Non-empty string value "username": "<<notEmptyString>>"
<<integer>> Integer value "age": "<<integer>>"
<<validAlgorithm>> JWT algorithm matching service.ini "alg": "<<validAlgorithm>>"
<<validTokenType>> JWT type matching service.ini "typ": "<<validTokenType>>"
<<validIssuer>> Issuer registered in service.ini "iss": "<<validIssuer>>"
<<validUnixTimestamp>> Valid Unix timestamp "exp": "<<validUnixTimestamp>>"

Exact Value Matching

If no rule syntax is used, the validator expects an exact match:

This requires the Content-Type header to be exactly application/json.


JWT Authentication

PumaAPI uses JWT Bearer tokens for authentication. Tokens must be sent in the Authorization header:

Token Structure

Generating Tokens

Use the Tokenizer class to generate new tokens:


Service Configuration

Create a service.ini file in your manifest directory:

Configuration Sections

Section Purpose
[ident] Service identity (issuer name)
[token] Default JWT header configuration
[auth] Registered issuers and their secret keys

Making Outbound API Calls

Use the Caller class to make authenticated requests to other services:


Certificate Object

After successful validation, the Certificate object provides access to sanitized request data:


Error Handling

PumaAPI uses the Rawr exception class for structured error handling:

HTTP Status Codes

Code Constant Description
400 Rawr::BAD_REQUEST Invalid request format or missing fields
401 Rawr::UNAUTHORIZED Invalid or missing authentication
403 Rawr::FORBIDDEN Access denied
404 Rawr::NOT_FOUND Resource or endpoint not found
405 Rawr::METHOD_NOT_ALLOWED HTTP method not supported
500 Rawr::INTERNAL_ERROR Server-side error

Error Response Format

Production (default):

Development (with PUMA_API_SEND_EXCEPTIONS_IN_RESPONSE):


Global Configuration Flags

โš ๏ธ Warning: These flags are intended for development only. Never enable them in production!

Define these constants in your bootstrap file before instantiating the API class. The presence of the constant enables the feature (the value is ignored).


Complete Usage Example

1. Project Structure

2. Apache Rewrite Rules (.htaccess)

3. Contract File (__manifest/post/auth/login.json)

4. Service Configuration (__manifest/service.ini)

5. Entry Point (index.php)

6. Controller (controllers/AuthController.php)


Security Considerations

  1. Keep service.ini secure - This file contains secret keys; ensure it's not web-accessible
  2. Use HTTPS - Always use SSL/TLS in production
  3. Rotate secrets regularly - Update JWT signing keys periodically
  4. Set short expiration times - Use reasonable exp values for tokens
  5. Disable development flags - Never use PUMA_API_* constants in production
  6. Validate all input - Define comprehensive contracts for all endpoints

API Reference

PumaAPI\Controller\API

Method Returns Description
__construct($manifestPath = false) API Initialize with optional manifest path
getCertificate() Certificate Get validated request certificate

PumaAPI\Model\Certificate

Method Returns Description
getRequestedMethod() string HTTP method (lowercase)
getRequestedRoot() string Controller/root segment
getRequestedResource() string Resource path
getRequestHeaders() array Validated request headers
getRequestBody() array Validated request body
getRequestedJWTHead() array JWT header claims
getRequestedJWTPayload() array JWT payload claims
getResponseContract() array Response contract definition

PumaAPI\Model\Tokenizer

Method Returns Description
__construct($configPath = false) Tokenizer Initialize with config path
generateNewToken($issuer, $head, $body) string Generate complete JWT
generateSignatureFor($issuer, $head, $body) string Generate signature only
getCurrentIssuer() string Get configured issuer
getCurrentAlgorithm() string Get configured algorithm
getCurrentTokenType() string Get configured token type
isAuthentic($tokenContent, $issuer) bool Verify token signature
validExpiryDate($tokenHead) bool Check if token is expired
extractJWT($headers) array Parse JWT from headers (static)

PumaAPI\Model\Caller

Method Returns Description
__construct($method, $url, $headers, $jwt, $body) Caller Initialize request
initRequest() void Execute the HTTP request
getResponse() array Get response (code, headers, body)
getJWTResponse() array Parse JWT from response

Important

This is a personal side project developed independently in my own time, using my own equipment and resources. It has no connection to any employer, client, or commercial work.


All versions of puma-api with dependencies

PHP Build Version
Package Version
Requires ext-json Version *
ext-curl Version *
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 pumasoft/puma-api contains the following files

Loading the files please wait ...