GithubHelp home page GithubHelp logo

slim-json-api's People

Contributors

baileylo avatar beamcode avatar bignall avatar bryant1410 avatar clicman avatar entomb avatar martemorfosis avatar mikebarlow avatar philzen avatar ulion avatar woolfg avatar zyles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slim-json-api's Issues

broken etags / 304 Not modified

Hey, thanks for the great little api. I just encountered a problem when using Slim's etags... when it is trying to return the 304 Not Modified, slim-json-api picks up the empty response body and sets an error.

I made a quick fix at line 72 of jsonApiMiddleware.php:

if ($app->response()->getStatus() != 304 && strlen($app->response()->body()) == 0) {

JsonApiView accessing undefined objects, method.

Hi,

When I call the view object from my own middleware class, the following error is called.

PHP Fatal error:  Call to a member function getMessages() on a non-object in /Users/ben/www/collateit/mvp/api/vendor/entomb/slim-json-api/jsonAPI/JsonApiView.php on line 42

which relates to this line:

$flash = $this->data->flash->getMessages();

presumably 'flash' is not an object?

Cheers
Ben

JSONP Support

Replace :
$app->response()->body(json_encode($response));
with :
if (($jsonCallback = $app->request()->get('callback')) !== null) {
$response = sprintf("%s(%s);", $jsonCallback, json_encode($response));
$app->response()->body($response);
}else{
$app->response()->body(json_encode($response));
}

jsonp

Please change jsonp "Content-Type" to "application/javascript"

public $contentTypeJson = 'application/json';
public $contentTypeJsonp = 'application/javascript';

if($jsonp_callback !== null){
$app->response()->header('Content-Type', $this->contentTypeJsonp);
$app->response()->body($jsonp_callback.'('.json_encode($response, $this->encodingOptions).')');
} else {
$app->response()->header('Content-Type', $this->contentTypeJson);
$app->response()->body(json_encode($response, $this->encodingOptions));
}

Dev 2.3 Release Support

The JSON encoding of $this->data doesn't work for the 2.3 branch of Slim. I've updated JsonApiView to use the new data accessor functions in \Slim\View. These functions are not backwards compatible, or I would've just made a pull request against master. You can find my code here.

Release?

Could we have a new release? :-)

I dislike defining non-absolute dependencies - like just tracking master of this repo...

Strict Mode errors

When strict mode is enabled - slim shows such error

Declaration of JsonApiView::render() should be compatible with Slim\View::render($template, $data = NULL)

problems with slim 2.6 - error template 200 not found

Hi,
i can't get the examples to work in slim 2.6. I used the "routing example". It seems the View is not set correctly. Slim throws an Exception .

Message: View cannot render `200` because the template does not exist
File: <<path>>\vendor\slim\slim\Slim\View.php

Can you confirm that it work with slim 2.6?

My Code:

function APIrequest(){
    $app = \Slim\Slim::getInstance();
    $app->config('debug', false);
    $app->view(new \JsonApiView());
    $app->add(new \JsonApiMiddleware());
}

$app->get('/api','APIrequest',function() use($app){
    $app->render(200,array(
            'msg' => 'welcome to my API!',
        ));
});

slim.after.router add header check

// Handle Empty response body
$app->hook('slim.after.router', function () use ($app) {
$res = $app->response();
if($res['Content-Type'] != 'application/octet-stream'){
if (strlen($app->response()->body()) == 0) {
$app->render(500,array(
'error' => TRUE,
'msg' => 'Empty response',
));
}
}
});

ERROR: could not find driver

I added it to composer to my current slim app, added the Middleware and the view, but now I get this error returned?

{"error":true,"msg":"ERROR: could not find driver","status":500}

What gone wrong? Thanks in advance

Uncaught exception 'Slim\Exception\Stop'

Hey, thanks for your tidy little API. I just installed it into my app, but I am receiving this error when using the JsonApi middleware + view...

PHP Fatal error:  Uncaught exception 'Slim\Exception\Stop' in /.../vendor/slim/slim/Slim/Slim.php:1017
Stack trace:
#0 /.../vendor/entomb/slim-json-api/jsonAPI/JsonApiView.php(86): Slim\Slim->stop()

I am calling the view render from another middleware's call() function as:

$this->app->render(401, array(
                'error' => TRUE,
                'message' => 'Access denied.'
                ));

Wondering why this happens and where would be the proper place to catch the exception?

Any chance of a new release?

Hi folks:

I'm sure I'm not the only one who's trying to implement a JSON API-compliant API using Slim and this (rather excellent) library.

As part of this spec, the Content-Type header should be set to application/vnd.api+json rather than application/json. There's a patch in the master branch since January which implements this tiny change but there's no release since August last year.

I've changed the composer.json for my project to require dev-master, but longer-term even a loose association with a release version would be better if possible. Any chance of a release at any stage? Cheers!

Slim 3.0

With the Slim 3.0 release candidate out, I've tried to get this to work but I'm getting

Fatal error: Class 'Slim\Middleware' not found in /var/www//vendor/entomb/slim-json-api/jsonAPI/JsonApiMiddleware.php on line 23

There have been some large changes to how middleware works, http://www.slimframework.com/docs/concepts/middleware.html

Will this package be updated to work with 3.0? I love it and want to keep using it

Slim 3 Class 'Slim\View' and 'Slim\Middleware' not found

Fatal error: Class 'Slim\View' not found in C:\xampp\htdocs\slim\test\vendor\entomb\slim-json-api\jsonAPI\JsonApiView.php on line 24

Fatal error: Class 'Slim\Middleware' not found in C:\xampp\htdocs\slim\test\vendor\entomb\slim-json-api\jsonAPI\JsonApiMiddleware.php on line 23

Declaration of JsonApiView::render() should be compatible with Slim\View::render($template, $data = NULL)

Hello!
I have an issue with JsonApiView:
Declaration of JsonApiView::render() should be compatible with Slim\View::render($template, $data = NULL)

Installed via composer.
Error appears only if
ini_set ('error_reporting', E_ALL);

Test application:

ini_set ('error_reporting', E_ALL);
ini_set ('display_errors', '1');

require 'vendor/autoload.php';

use Slim\Slim;
use Slim\Middleware;
use Slim\Views\Twig;
$app = new Slim([
    'view' => new Twig(),
    'templates.path' => './public',
    'mode' => 'development',
]);
$app->add(new Middleware\ContentTypes());
function APIrequest() {
    $app = \Slim\Slim::getInstance();
    $app->view(new \JsonApiView());
    $app->add(new \JsonApiMiddleware());
}

$app->get('/api','APIrequest',function() use($app){
    //this request will have full json responses

    $app->render(200,array(
        'msg' => 'welcome to my API!',
    ));
});
$app->run();

Allow OPTIONS requests to have an empty body

Loving the library! Just a quick point, when my webapp requests the available OPTIONS I have my code set a 200 response and an appropriate header:

Allow:OPTIONS,GET

However because there is no body, this library sets the header as a 500 and create an error. Which probably shouldnt happen. Should be a simple case to detect the response type and prevent this?

Cheers
Ben

No distinction between array and object

I want rendering an array of object so i do :

$data = $sqlFetchArray;

$arr = (array) array();

foreach ($data as $t) {
 $arr[] = (object) array('id' => $t[0], 'name' => $t[1]);
}

$app->render(200, $arr);

But i still get json object and no array of json object.

{
 0: {id: 144, name: 'warlof'},
 1: {id: 201, name: 'elfaus'}
}

instead of

[
 {id: 144, name: 'warlof'},
 {id: 201, name: 'elfaus'}
]

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.