API

Startup API package provides it's core APIs through HTTP RESTful web services at  URL.

Applications using Startup API can also expose it's functionality through a centralized API handler.

All endpoints registered with application instance are listed at  URL, interactive API console is a feature for future development.

Making calls
To make API calls, you need to provide a required endpoint slug as  parameter, for example:

GET http://www.myapp.com/users/api.php?call=/startupapi/v1/user

which will provide information for a currently logged in user.

Passing parameters
Each endpoint might accept additional parameters which are listed below the endpoint. For GET endpoints, you can just add URL-encoded parameters to a query string:

GET http://www.myapp.com/users/api.php?call=/startupapi/v1/user&id=1

For methods that support request body (e.g. POST or PUT), you can send them in as a form-url-encoded values.

Parameters can be optional or required and some can also support multiple values, you can send multiple values for the same parameter, but just using it multiple times in the URL like:

GET http://www.myapp.com/users/api.php?call=/startupapi/v1/user&id=1&id=2&id=3

Raw request bodies
Some endpoints might also accept content as raw request body, each endpoint is responsible for parsin and understanding the content of that body, if necessary.

Responses
Response of the call is a JSON object with  value containing information about the request and   value containing the result of the API call.

Errors
If API call was successful,  property will be set to   and   will contain result of the call.

Otherwise,  will be set to   and   will contain error message, with optional error code in. In case of an error  will not be set.

HTTP response code will also be set to a corresponding error code.

Implementing your own endpoints
Your application can expose it's own APIs through the same mechanism and benefit from all the authentication methods and handling infrastructure that is already built for Startup API's own infrastructure.

Implementing Endpoints
In order to implement your own endpoint you need to subclass  class or one of it's subclasses, e.g..

Call Parent's Constructor
In your implementation call parent's constructor and specify following parameters:
 * - URL-friendly ID that should start with the slash can contain slashes, dashes, latin letters and numbers, e.g.
 * - description of the endpoint to be displayed on documentation page

Set Endpoint Parameters
If your method supports parameters, you should register them in constructor by setting  to an associative array of name-value pairs:

Override method
Implementing the endpoint is as simple as overriding  PHP method.

First line should be calling parent's  method

Getting User Object
If you subclassed  then you can easily get currently authenticated user by capturing the value returned from parent's   method.

Return value
Return value for the call is a simple nested associative array with any level of nesting.

It will be combined with some request-related metadata and returned as a value to  key in JSON payload.

ObjectNotFoundException
You can throw  to indicate that object requested was not found in the system (will return 404)

Register Your Endpoint
After you implemented an endpoint class, you need to register and instance of it with Startup API in your  file.

Create API Namespace
In order to register an endpoint, you first need to create an API Namespace object representing all of your calls: