All Projects → colymba → Silverstripe Restfulapi

colymba / Silverstripe Restfulapi

Licence: bsd-3-clause
SilverStripe RESTful API with a default JSON serializer.

Projects that are alternatives of or similar to Silverstripe Restfulapi

Nodeapi
Simple RESTful API implementation on Node.js + MongoDB.
Stars: ✭ 719 (+1041.27%)
Mutual labels:  api, restful
Go Base
Go RESTful API Boilerplate with JWT Authentication backed by PostgreSQL
Stars: ✭ 928 (+1373.02%)
Mutual labels:  api, restful
Apidoc
RESTful API 文档生成工具,支持 Go、Java、Swift、JavaScript、Rust、PHP、Python、Typescript、Kotlin 和 Ruby 等大部分语言。
Stars: ✭ 785 (+1146.03%)
Mutual labels:  api, restful
V8 Archive
Directus Database API — Wraps Custom SQL Databases with a REST/GraphQL API
Stars: ✭ 486 (+671.43%)
Mutual labels:  api, restful
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (-22.22%)
Mutual labels:  api, restful
Snake
🐍 一款小巧的基于Go构建的开发框架,可以快速构建API服务或者Web网站进行业务开发,遵循SOLID设计原则
Stars: ✭ 615 (+876.19%)
Mutual labels:  api, restful
Yet Another Rest Client
YARC (Yet Another REST Client) is an easy-to-use REST Client for Google Chrome.
Stars: ✭ 23 (-63.49%)
Mutual labels:  api, restful
Horse
Fast, opinionated, minimalist web framework for Delphi
Stars: ✭ 295 (+368.25%)
Mutual labels:  api, restful
Python Api Development Fundamentals
Develop a full-stack web application with Python and Flask
Stars: ✭ 44 (-30.16%)
Mutual labels:  api, restful
Es6 Express Mongoose Passport Rest Api
Lightweight boilerplate for Node RESTful API, ES6, Express, Mongoose and Passport 🎁
Stars: ✭ 36 (-42.86%)
Mutual labels:  api, restful
Typescript Rest
This is a lightweight annotation-based expressjs extension for typescript.
Stars: ✭ 458 (+626.98%)
Mutual labels:  api, restful
Api Strategy
Equinor API Strategy
Stars: ✭ 56 (-11.11%)
Mutual labels:  api, restful
Koa Rest Api Boilerplate
💯 Boilerplate for Node.js Koa RESTful API application with Docker, Swagger, Jest, CodeCov and CircleCI
Stars: ✭ 420 (+566.67%)
Mutual labels:  api, restful
Koa2 Api Scaffold
一个基于Koa2的轻量级RESTful API Server脚手架。
Stars: ✭ 694 (+1001.59%)
Mutual labels:  api, restful
Go Api Boilerplate
Go Server/API boilerplate using best practices DDD CQRS ES gRPC
Stars: ✭ 373 (+492.06%)
Mutual labels:  api, restful
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+1149.21%)
Mutual labels:  api, restful
Php Curl Class
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
Stars: ✭ 2,903 (+4507.94%)
Mutual labels:  api, restful
Restful Doom
HTTP+JSON API hosted inside the 1993 DOOM engine!
Stars: ✭ 263 (+317.46%)
Mutual labels:  api, restful
Lor
a fast, minimalist web framework for lua based on OpenResty
Stars: ✭ 930 (+1376.19%)
Mutual labels:  api, restful
Flask Restx
Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
Stars: ✭ 1,050 (+1566.67%)
Mutual labels:  api, restful

⚠️ I haven't been able to give as much love as I would like to these repos as they deserve. If you have time and are interested to help maintain them, give me a shout. 🚨

SilverStripe RESTful API

Build Status

This module implements a RESTful API for read/write access to your SilverStripe Models. It comes bundled with a default Token Authenticator, Query Handler and JSON Serializers, and can be extended to your need and to return XML or other content type via custom components.

API URL structure

Action HTTP Verb URL
Find 1 record GET api/Model/ID
Find multiple records GET api/Model?param=val&__rand=1234
Update a record PUT api/Model/ID
Create a record POST api/Model
Delete a record DELETE api/Model/ID
- - -
Login & get token n/a api/auth/login?email=***&pwd=***
Logout n/a api/auth/logout
Password reset email n/a api/auth/lostPassword?email=***
- - -
Custom ACL methods n/a api/acl/YOURMETHOD

Model being the class name of the model you are querying (name formatting may vary depending on DeSerializer used). For example with a model class named Book URLs would look like:

  • api/Book/33
  • api/Book?title=Henry
  • api/Book?title__StartsWith=Henry
  • api/Book?title__StartsWith=Henry&__rand=123456&__limit=1
  • api/Book?title__StartsWith=Henry&__rand=123456&__limit[]=10&__limit[]=5

The allowed /auth/$Action must be defined on the used Authenticator class via the $allowed_actions config.

Requirements

Quick features highlight

What's all this?

RESTfulAPI

This is the main API Controller that receives all the requests, checks if authentication is needed and passing control to the authenticator if true, the resquest is then passed on to the QueryHandler, which uses the DeSerializer to figure out model & column names and decode the eventual payload from the client, the query result is then passed to the Serializer to be formatted and then returned to the client.

If CORS are enabled (true by default), the right headers are taken care of too.

Components

The RESTfulAPI uses 4 types of components, each implementing a different interface:

  • Authetication (Authenticator)
  • Permission Management (PermissionManager)
  • Query Handler (QueryHandler)
  • Serializer (Serializer)

Default components

This API comes with defaults for each of those components:

  • TokenAuthenticator handles authentication via a token in an HTTP header or variable
  • DefaultPermissionManager handles DataObject permission checks depending on the HTTP request
  • DefaultQueryHandler handles all find, edit, create or delete for models
  • DefaultSerializer / DefaultDeSerializer serialize query results into JSON and deserialize client payloads
  • EmberDataSerializer / EmberDataDeSerializer same as the Default version but with specific fomatting fo Ember Data.

You can create you own classes by implementing the right interface or extending the existing components. When creating you own components, any error should be return as a RESTfulAPIError object to the RESTfulAPI.

Token Authentication Extension

When using TokenAuthenticator you must add the TokenAuthExtension DataExtension to a DataObject and setup TokenAuthenticator with the right config.

By default, API authentication is disabled.

Permissions management

DataObject API access control can be managed in 2 ways. Through the api_access YML config allowing for simple configurations, or via DataObject permissions through a PermissionManager component.

A sample Group extension GroupExtension is also available with a basic set of dedicated API permissions. This can be enabled via config or you can create your own.

By default, the API only performs access control against the api_access YML config.

Config

See individual component configuration file for mode details

Here is what a site's config.yml file could look like:

---
Name: mysite
After:
    - 'framework/*'
    - 'cms/*'
---
# API access
Artwork:
  api_access: true
Author:
  api_access: true
Category:
  api_access: true
Magazine:
  api_access: true
Tag:
  api_access: 'GET,POST'
Visual:
  api_access: true
Image:
  api_access: true
File:
  api_access: true
Page:
  api_access: false
# RestfulAPI config
Colymba\RESTfulAPI\RESTfulAPI:
  authentication_policy: true
  access_control_policy: 'ACL_CHECK_CONFIG_AND_MODEL'
  dependencies:
    authenticator: '%$Colymba\RESTfulAPI\Authenticators\TokenAuthenticator'
    authority: '%$Colymba\RESTfulAPI\PermissionManagers\DefaultPermissionManager'
    queryHandler: '%$Colymba\RESTfulAPI\QueryHandlers\DefaultQueryHandler'
    serializer: '%$Colymba\RESTfulAPI\Serializers\EmberData\EmberDataSerializer'
  cors:
    Enabled: true
    Allow-Origin: 'http://mydomain.com'
    Allow-Headers: '*'
    Allow-Methods: 'OPTIONS, GET'
    Max-Age: 86400
# Components config
Colymba\RESTfulAPI\QueryHandlers\DefaultQueryHandler\DefaultQueryHandler:
  dependencies:
    deSerializer: '%$Colymba\RESTfulAPI\Serializers\EmberData\EmberDataDeSerializer'
Colymba\RESTfulAPI\Serializers\EmberData\EmberDataSerializer:
  sideloaded_records:
    Artwork:
      - 'Visuals'
      - 'Authors'

Todo

  • API access IP throttling (limit request per minute for each IP or token)
  • Check components interface implementation

License

BSD 3-clause license

Copyright (c) 2018, Thierry Francois (colymba) All rights reserved.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].