The Fastest Way to Mock a REST API JSON Response

You’ve just found the Fastest Way to Mock a Rest API JSON Response. I know time is precious so I’ll be quick:

First Step: Install the Server

sudo npm install -g json-server

Second Step: Create the Mock Response

This will be depending on what you want the fastest mock REST API to be.
Create it in a file called db.json

  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  "profile": { "name": "typicode" }

Third Step: Run the Server

json-server --watch db.json

Fourth Step: Test the API

USe Anything you want but postman, curl, python request will work well.

>>>import requests

You Can check your JSON Formatting with this tool

There we Go!

You have just seen the Fastest Way to Mock a REST API JSON Response.

Sources: Json Server Github

Why is Laravel 5 So Bad?

Coming from Zend 1 and Yii 1, I find Laravel has made things complicated for itself. It has also tried to be too much of a unique item. Let me explain why Laravel 5 is so bad.


Who am I to Comment

Well I’ve used Yii 1 and Zend Framework extensively. You can take a look at my Yii share trading site. I have also dabbled, gone through a video tutorial and built a simple site and API with it, with Ruby on Rails 4. I have also worked with Magento (Sigh) and the Django Rest Framework.

So pretty much the best non-js server-side frameworks. So with decent standing I thought I would take a look at Taylor Otwells master piece, Laravel 5, before I check out Yii 2. Unfortunately in some respects I am disappointed (take note I’m only about 20% through an ebook teaching laravel)

The Good of Laravel 5

  • It leverages off other new and cool stuff: embracing npm, task runners, dev environments
  • It uses the best (not just the easiest or most popular) out of the “new and cool stuff”
  • Homestead A great development environment and cli tool

The Bad of Laravel 5

  • You have to manually create a view and action, no generator
  • laravel and php artisan command line utilities could be combined into a single laravel command
  • The directory structure is strange to the point of complexity. Controllers for example are not found in the app folder but in the app/Http folder. Views are not in the app/Http directory next to controllers, they are in a separate top level folder Resources/view

The Ugly of Laravel 5

    • It wraps everything as its own special thing: homestead is a wrapper for vagrant, elixir is a wrapper for gulp. Just use the tools as they are because it will allow php devs to work on a host of other frameworks and technologies.
    • Strange View and layout directives (maybe I need to get used to them): @yield, @extends, @section, @show, @parent. It can get rather complicated.
    • The Blade templating system, as above, declaring variables in views makes it seem like you are using angular, react or meteor. Sometimes I think php short tags make things simpler than: @foreach, @endforeach, @if, @else, @elseif, endif.
    • No generic route for Controller/Action/Id

Update (26-10-2015)

Another thing to notice is the caching of views. This feature is on by default and you have to hack it to turn off view caching. What this means is you can’t pinpoint in what file an error has occurred (usually a typo). So you end up with a crap error like:


Summing it Up

Laravel 5 is probably the best PHP Framework. It’s still not great though but it a massive step in the right direction. I can’t help but think that yii2 may have got the rails to PHP conversion done a bit better. You will have to know Laravel 5 though because of this report, so might as well start linking it.

The best feature of Laravel is by far the Standard Local Development Environment: Homestead.
So instead of having to install all these crap PHP extensions and what not you can create a repeatable local laravel dev environment that just works. Furthermore if you use the homestead composer tool, creating shared folders and adding multiple sites to virtual host id a breeze. It makes development much better. Unfortunately frameworks like Django and Rails aren’t as Vagrant friendly and hence you have to create an ansible script to setup your boxes which is a bit of a schlep.

Update 2 (29-10-2015)

There is also the issue of the blade templating system. Which is awesome, except that it is not strict and allows any old crap to pass.

Such as ending a section with @endsection instead of @stop

or specifying a section with:

@section('title', 'Establishment Name')@stop

Instead of:

Establishment Name

No error messages, and nothing in the logs. However it creates a huge problem in that…the session cookie is not set correctly due to template errors.

So now you will never be able to maintain a logged in session and all forms will now fail with a:

TokenMismatchException in VerifyCsrfToken.php line 46


laravel CSRF Token Mismatch Excpetion

Also you will find it is very hard to peruse the templates to find where the actual problem is and you will have to resort to deleting large portions of the template until the problem code is found.

So I’ve created this git repo, so you can lint the blade templates and find the issue. Why Laravel doesn’t have one built in with elixir is anyone’s guess.

How to Fix the Vagrant Error: Failed to mount folders in Linux guest.

How to Fix: Failed to mount folders in Linux guest

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

The cause

The cause could be if you upgraded your box.


vagrant plugin install vagrant-vbguest