0 Best Reply Awards

  • Member Since 4 Years Ago
  • 1 Lesson Completed
  • 2 Favorites

24th May, 2015

tjoskar left a reply on AMQP With Laravel • 3 years ago

Hi xsmall,

I don't know if you misunderstand my question or if I misunderstand your answer. I want to find a way to communicate between laravel instance and node js (without HTTP). Sure, I could establish a websocket connection between a node js instance and laravel with Larapush but it feels backwards.

I saw, however, that Larapush is using ZeroMQ and that maybe the way to go for me. Thanks for that!

20th May, 2015

tjoskar started a new conversation Laravel And RPC • 3 years ago


I like the idea of micro services and I want to use it with laravel. I am thinking of creating a thin API-layer with lumen (or laravel) and then create a batch of services, running its own instance of lumen who only does one thing (but does it very well).

For instance, lets say I have an endpoint PUT /some_crazy_heavy_image_processing/. I don’t want to have the logic of that endpoint in the same project as the HTTP API. Instead I want to separate it to a different project and to a different instance of lumen/laravel.

I can do this quite easy by just pushing jobs on the queue and let some other pick it up (the api-endpoint push the job on the queue and some other lumen instance pick it up) but the problem comes when the client are expecting a result from the API. In these cases, I have to use RPC or similar but from what I can see, laravel are not supporting RPC out of the box (?) .

I can use php-amqplib with rabbitmq ( but I don't want to miss all great features that laravels queue handler provides (like: retries, delaying, etc) and I don't want to use two different library for queues.

Now to my question: Have anyone used laravel and a queue based RPC-handler? And want to share their experience.

My other option is to use JSON-RPC over HTTP but then all services are required to have its own API interface and I don’t want that.

Thanks and have a good one. // Oskar

2nd February, 2015

tjoskar started a new conversation AMQP With Laravel • 3 years ago


I'm thinking of building an API application that work something like this: – At front I have a NodeJS app (Express or (Sails.js)[] or similar) which is only a thin and dumb layer that receives http requests and forwards it to an Laravel app.

Has anyone here worked with AMQP (and laravel) and could point me in the right direction? I found this repo: but it seems that it only uses the queue functionality, not the possibility to communicate between apps.

The reason why I want to use NodeJS and Laravel is: 1. NodeJS is fast and have low latency 2. Today I have NodeJS side by side with laravel (apache proxy). It would be nice to only have one application accessible by HTTP. 3. I already have written a big amount of business logic in laravel and I want to keep that. 4. I like the idea of Micro Service Architecture 5. I want to learn

28th January, 2015

tjoskar left a reply on API Version Control In Header • 3 years ago

@JeroenVanOort , I believe it's best practice. The URL should uniquely identify the resource, the version has nothing to do with that. There is an interesting discussion on the topic here:

tjoskar left a reply on API Version Control In Header • 3 years ago

@yayuj, sure.

This may not be the prettiest solution but it's good enough for now.

Route::group(['middleware' => 'api-version'], function()
    // Movie
    Route::get('movie/{id}', '{api-namespace}\MovieController@show');
    Route::put('movie/{id}', '{api-namespace}\MovieController@update');
// ApiVersionMiddleware.php
public function handle($request, Closure $next)
    $route = $request->route();
    $actions = $route->getAction();

    $requestedApiVersion = ApiVersion::get($request);
    if (!ApiVersion::isValid($requestedApiVersion)) {
        throw up_some_error;

    $apiNamespace = ApiVersion::getNamespace($requestedApiVersion);

    $actions['uses'] = str_replace(


    return $next($request);
// ApiVersion.php
class ApiVersion {

    private static $valid_api_versions = [
        3 => 'v3'

     * Resolve the requested api version.
     * @param  \Illuminate\Http\Request  $request
     * @return integer
    public static function get($request) {
        return intval($request->header('api-version'));

     * Determines if a version is valid or not
     * @param integer $apiVersion
     * @return bool
    public static function isValid($apiVersion) {
        return in_array(

     * Resolve namespace for a api version
     * @param integer $apiVersion
     * @return string
    public static function getNamespace($apiVersion)
        if (!self::isValid($apiVersion)) {
            return null;

        return self::$valid_api_versions[$apiVersion];


25th January, 2015

tjoskar left a reply on API Version Control In Header • 3 years ago

I just found that one can check the header informtion in the route file:

$version = Request::header('api-version');
if ($version === '3') {
    Route::resource('user', 'v3\UserController');
} elseif ($version === '2') {
    Route::resource('user', 'v2\UserController');

Is there a better way?

tjoskar started a new conversation API Version Control In Header • 3 years ago


I'm working on a api application and wants to version controll it by header information eg, api-version: 3.

I know its possible to include this information in the url with Route::group like:

Route::group(['prefix' => 'v3'], function() {
    Route::resource('user', 'v3\UserController');

But I don't want to have this information in the URL.

I suppose it's possible to do something like this:

// Routes
Route::resource('user', 'UserController');

// UserController.php

private $userRepository;

function __construct() {
    $apiVersion = Request::header('api-version');
    $this->userRepository = App::make('userRepository-' . $apiVersion);

public function show($id)
    return $this->userRepository->get_resource($id);

However, this method do not scaling very well.

What I realy wants is something like this:

class VersionMiddleware {

    public function handle($request, Closure $next)
    $apiVersion = $request->header('api-version');
        if ($apiVersion === 3)
                // This will make laravel to use the correct controller in
                // namespace /v3
        return useVersionThree($request);
        elseif ($apiVersion === 2)
    elseif ($apiVersion === 1)



// The version-middleware instancinate the correct version of UserController
Route::get('user/{id}', ['middleware' => 'version', 'uses' => 'UserController@show']);

Is that possible?

Edit Your Profile

Want to change your profile photo? We pull from