Coder Social home page Coder Social logo

developit / tinyapi Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 1.0 108 KB

TinyAPI is a very small PHP framework for creating APIs. It maps URLs to methods of classes, so you can write real PHP. Write portable classes that return associative arrays, and use TinyAPI to expose them to the web with automatic output formatting. There is also magic.

Home Page: http://jasonmillerdesign.com/tinyapi/

JavaScript 2.27% PHP 97.73%

tinyapi's Introduction

TinyAPI is a very small PHP framework for creating APIs. It maps URLs to methods of classes, so you can write real PHP. Write portable classes, and use TinyAPI to expose them to the web. There is also magic.

TinyAPI consists of 6 files/directories that should be uploaded to the directory you want to turn into an API.

.htaccess
index.php
public/
tinyapi/
tinyapi/main.php
tinyapi/lib/formatters/xml.inc.php

Beyond that, all you have to do is write your code. There is no special sauce. Place PHP scripts into the public/ directory that return either a static class (the String class name actually), an instance, or a regular class. TinyAPI will get to the public methods on that class and call them based on requested URLs.

Routing is simple. Primarily, a URL is mapped directly to your folder structure in public/. That means example.com/api/test/test2/test3 maps to the index() method for the class in public/test/test2/test3.php.  If TinyAPI can't find that, it will try looking for a test3() method defined in public/test/test2.php.  Failing that, it will try to call a test2_test3() method on the class in public/test.php.  Each time a routing attemp fails, TinyAPI will try to call an error() method on the class it finds - if that method exists, it gets control of the request.

Sub-routing works exactly the same way, with one added feature. Sub-routing is a way of accessing the methods you have exposed through TinyAPI without making a secondary HTTP request. When requesting sub-routed methods, you will get the array returned from the method, or FALSE if it failed. To request a sub-routed method, call API::exec('url/of/method', $optional_get, $optional_post).  You can check out a typical example in public/test.php.

I hope you find this useful! You can reach me at jason [@] dvlpt [.] com

tinyapi's People

Contributors

developit avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

kazantip151

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.