Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • REST API in joomla 3.4 with SLIM Framework PART 1

    • 0
    • 1
    • 0
    • 1
    • 2
    • 0
    • 0
    • 0
    • 2.79k
    Comment on it

    Say Hello to Slim World

    Today I am going to reveal first part of building REST API in Joomla 3.4 with SLIM Framework. To get started with Slim, here is small introduction about slim framework that is written on SLIM official website. "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs."

    SLIM Hello World Application look like this.

    // create new Slim instance
    $app = new Slim();
    
    // add new Route
    $app->get("/", function () {
        echo "<h1>Hello Slim World</h1>";
    });
    
    // run the Slim app
    $app->run();
    

    Your first Slim application is ready now. If you access index.php through your browser, you should see a big Hello Slim World.

    To use Slim in Joomla, Include slim.php to use slim in your application, as a result slim will autoload all other necessary files that it needs, after this add your routes and create one or more instances of the Slim object.

    To add SLIM Framework in your Joomla 3.4 Library Add this code in your composer.json file

    {
        "require": {
            "slim/slim": "2.*"
        }
    }
    

    and update your composer by

    composer update
    

    from your command line.

    if you cant find composer.json file in your Joomla root directory, don't worry currently Joomla is not shipping composer.json file, but you can add by copy bellow code.

    {
        "name": "joomla/joomla-cms",
        "type": "project",
        "description": "Joomla CMS",
        "keywords": ["joomla", "cms"],
        "homepage": "https://github.com/joomla/joomla-cms",
        "license": "GPL-2.0+",
        "config": {
            "vendor-dir": "libraries/vendor"
        },
        "require": {
            "php": ">=5.3.10",
            "joomla/application": "~1.2",
            "joomla/di": "~1.2",
            "joomla/registry": "~1.2",
            "joomla/string": "~1.2",
            "joomla/uri": "~1.1",
            "ircmaxell/password-compat": "1.*",
            "leafo/lessphp": "0.3.9",
            "phpmailer/phpmailer": "5.2.8",
            "symfony/yaml": "2.*",
            "slim/slim": "2.*",
            "slim/extras": "~2.0"
        },
        "require-dev": {
            "phpunit/phpunit": "4.1.*"
        },
        "autoload": {
            "psr-0": {
                "API":        "api/"    
            }
        }
    }
    

    Now create API directory in your root name it as API, directory will look like this.

    your-project-name/
      - administrator 
      - api
            -- V1
                --- index.php
            -- JsonApiMiddleware.php
            -- JsonApiView.php
      - bin
      - components
      - images
      - includes
      - language
      - layouts
      - libraries/
        -- vendor
      - logs
      - media
      - modules
      - plugins
      - templates
      - tmp
      composer.json
      composer.lock
      index.php
      configuration.php
    

    Slim library has been auto loaded, now we wil write our API using slim framework in next part.

    Part 2 coming soon stay tuned!

 2 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: