GithubHelp home page GithubHelp logo

luracast / restler Goto Github PK

View Code? Open in Web Editor NEW
1.4K 88.0 317.0 9.51 MB

Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and/or RESTful API

Home Page: http://luracast.com/products/restler/

License: GNU Lesser General Public License v2.1

Makefile 1.12% PHP 15.59% CSS 5.74% JavaScript 71.67% HTML 4.04% Gherkin 1.36% Blade 0.21% Twig 0.26% Shell 0.01%
restler php phpdoc-comments html-format php-fpm composer json-format jsonp

restler's People

Contributors

amilkov avatar arul- avatar camlafit avatar chh avatar dazzhands avatar gitter-badger avatar grosch avatar haegar avatar janez89 avatar joelrsimpson avatar joshuadwire avatar justericgg avatar kocsismate avatar kschu91 avatar letsbyteit avatar linux019 avatar logical-steps avatar michaelcgn avatar myalban avatar nickl- avatar nickstallman avatar ogodon avatar qepic42 avatar rahulkumarsaini avatar richardeaxon avatar shaneneuerburg avatar themy3 avatar tomahock avatar tommyf avatar yankeeinlondon 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  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

restler's Issues

xmlformat doesn't work

Hi,

When i select the xmlformat with

$r->setSupportedFormats('JsonFormat', 'xmlformat','yamlformat');

It gives an error.

The reason is that it expects the class to be in a sub folder.
I had to create the folder xmlformat and put the class file in there to make it work.

I know its a minor thing but will need to be fixed.

Cheers.

Add an Authentication Class from Custom Folder

How do you add an authentication class that is not in the root directory for your app using addAuthenticationClass?

addAuthenticationClass only works when my auth class is in the root directory.

I have tried adding the optional parameter of $base_path but it has not worked.

Escape chars added to post input

Hi,
If I POST a raw body like
$data='"one","two""three","four""five","six";

Then the data in the POST array gets escaped like
[data] => "one","two""three","four""five","six"

Is there a way to disable this behaviour without breaking the code ?

Restler php client

For those who are interested in a tiny example of a php restclient demonstrating all VERBS you may find it here : http:// www.eduh.nl/restler_client.zip
Problem with browser based restclients like chrome webconsole is that they sometimes malform your requests.

File Uploads

Does the current Restler support file uploads and if so, how do i do it?
If not, why not add it to the next version?

API Versioning with Restler v2.x

A couple of people talked about versioning so I thought i'd add my way of doing it so far. It has worked great and no issues that I have come accross. please do give feedback and let me know if you have any suggestions for improvement:

basic structure:

WEBROOT/
WEBROOT/API/
WEBROOT/API/lib/ (all restler files here, shared for any version of API)
WEBROOT/API/index.php (main router)
WEBROOT/API/v1/* (all files for version 1)
WEBROOT/API/v2/* (etc, for version 2)

Note: each version directory includes its own "routes" file. Otherwise I was unable to add/remove functions from one version to the next of the API.

Example index.php:

<?php

$DefaultVersion = "1";          // Default production version when called from the "public" url.  REST dictates you should include the version from what I know, but I am maintaining a default URL.
$Request_Split = explode("/",$_SERVER['REQUEST_URI']);  // Split request URI
$Version = $Request_Split[2].'/';               // In my case the URIs are /API/vXX/ so Version is the 2nd argument.  This should be changed for some sort of route map such as /API/:version or something…
if (($Version[0] == "v") && is_numeric($Version[1])){   // Basic checks so we don't try and interpret some injection (../..) nor interpret method calls as API version (this requires version to start with "v[somenumber]", otherwise assumes default version.
    set_include_path($Version);
}else{                              // no version specified, use default one… this way we can support API/v1/call and API/call
    set_include_path("v".$DefaultVersion);
    $Version = '';
}

/*
*  Whatever common files you want to include, it may be best to move these into the routes file...
*
******require_once 'NewLibs/Base/LogLib.php';

******require_once 'NewLibs/Base/DBLib.php'; 
*/

require_once 'lib/restler.php';

#set autoloader
#do not use spl_autoload_register with out parameter
#it will disable the autoloading of formats
spl_autoload_register("spl_autoload");

$r = new Restler();
$r->setSupportedFormats('JsonFormat', 'XmlFormat');

require_once 'routes.php';

$r->addAuthenticationClass('Authentication');


$r->handle();

And now for routes.php (repeat this file inside each application version directory:

<?php
require_once "NewLibs/Base/newversion.php";

$r->addAPIClass('someroute',$Version.'someroute');
$r->addAPIClass('teste',$Version.'teste');  // BEWARE TO HAVE EXACTLY THE SAME NAMES IN BOTH... dont mix upper/lower, etc.. make it identical!  An idea may be to use an array, but I just make sure when I add the routes... (an array and a foreach to addapiclass using the same array element so it is passed exactly the same).

I hope this is of use to someone... just wanted to give a bit back ;)

restler protection and parameters

Hi!

Great job that you did with restler! :-)

But is there a way to protect functions using parameters?

Example:

<?php
class Simple{

protected function test ($parameter){
   return $parameter;
}

}

will not work...or I do not enter the good url?!

index.php/simple/test/param?key=thekey
even index.php/simple?key=thekey/test/param

Thanks in advance!

Kevin

Authentication with ACL

Hi,

Like i said on Twitter i'm searching for a more extensive way of authentication.
In this case i want the users to authenticate them selves so i know what rights that user has.
each user can have different rights to different REST functions.

I could do HTTP AUTH, and use that to build up the ACL and check that when a REST call is done ?
Or is there a cleaner way ?

Error

Warning: get_class() expects parameter 1 to be object, string given in 
/nfs/c07/h03/mnt/111822/domains/labs.fathihadi.net/html/restler/restler/restler.php on line 335

Fatal error: Call to a member function getExtension() on a non-object in
/nfs/c07/h03/mnt/111822/domains/labs.fathihadi.net/html/restler/restler/restler.php on line 337

DELETE example

Hi,
Can't get the DELETE example working. I send a DELETE and it looks the $id is not transferred to

function delete($id=NULL) {
    return $this->dp->delete($id);
}

Tried to {"id":"2"} or {"id":2} in a request body.

Post request mapping

I have a testclass as below and I'm wondering why I can't use the function anotherpost() with a post request
So get+anotherget are returning as expected when using a GET request.
When I do a POST request with the url ....../test/anotherpost it returns 404 ...or am I misunderstanding something in the concept of mapping the methods ?

<?php
class Test
{

    function post() 
    {
        return "Hello Post";
    }
    function anotherpost() 
    {
        return "Hello Another Post";
    }
    function anotherget() 
    {
        return "Hello Another Get";
    }
    function get() 
    {
        return "Hello Get";
    }   
}
?>

yamlformat not working (files not found)

Fix-

on line 121 of yamlformat/sfyaml.php change 'sfyamldumper.php' to all lowercase
rename yamlformat/sfyamlInline.php to yamlformat/sfyaminline.php (all lowercase)

Thanks!

jsonp support?

This would be quite useful to get around the browser's cross-domain restrictions when making AJAX requests. I can't seem to find any documentation, other than the small bundled examples.

Strict Standards call_user_func() expects parameter 1 to be a valid callback

On XAMPP using PHP 5.3.8 too.


Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method DefaultResponse::__formatError() should not be called statically in C:\xampp\htdocs\xampp\fish\restler.php on line 293
{ "error": { "code": 401, "message": "Unauthorized" } }

Assign a Variable to JSON

Hello,

I have a need to assign the output of an API call to a variable name. Here is an example of output of what I have now.

{
  "places": [
    {
      "id": 1,
      "title": "Some Discount Thing",
      "store": "Villa Park Mall",
      "description": "Cras justo odio, dapibus ac facilisis in, egestas eget quam.",
      "lat": "41.848694",
      "lng": "-87.933960",
      "photo": "photo.jpg",
      "author_id": "1",
      "user": "test",
      "name": "test",
      "expire_date": "04-02-2012",
      "distance": "14.7360052686885"
    },
    {
      "id": 2,
      "title": "my title",
      "store": "my store",
      "description": "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.",
      "lat": "42.148693",
      "lng": "-86.161629",
      "photo": "photo.jpg",
      "author_id": "1",
      "user": "test",
      "name": "test",
      "expire_date": "04-28-2012",
      "distance": "78.6709865687144"
    }
  ]
}

Here is what I need the output to look like...

var myvar = {
  "places": [
    {
      "id": 1,
      "title": "Some Discount Thing",
      "store": "Villa Park Mall",
      "description": "Cras justo odio, dapibus ac facilisis in, egestas eget quam.",
      "lat": "41.848694",
      "lng": "-87.933960",
      "photo": "photo.jpg",
      "author_id": "1",
      "user": "test",
      "name": "test",
      "expire_date": "04-02-2012",
      "distance": "14.7360052686885"
    },
    {
      "id": 2,
      "title": "my title",
      "store": "my store",
      "description": "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.",
      "lat": "42.148693",
      "lng": "-86.161629",
      "photo": "photo.jpg",
      "author_id": "1",
      "user": "test",
      "name": "test",
      "expire_date": "04-28-2012",
      "distance": "78.6709865687144"
    }
  ]
};

If this is not possible, could I use JSONP to wrap a function and then some how to make the function convert to a variable? Any thoughts?

Keep getting "No input file specified"

Hi there,

After a lot of searches i stumbled upon this great rest server and figure it out in minutes that this is exactly what i needed for my project.

Only problem is i can't make it work as expected. I have uploaded it on a server on goddaddy and when i try to access something like http://citytravelr.com/client_api/index.php/user or http://citytravelr.com/client_api/index.php/user/inserUser i get a 404 Not Found and in browser it says No input file specified.

Also when i try to access http://citytravelr.com/client_api/index.php i get a 404 Not Found, and in browser says Firefox can't find the file at http://citytravelr.com/client_api/index.php.

Then i said that maybe its better to try with one of your samples out of the box, but i get same behavior. You can see it here http://citytravelr.com/_005_protected_api/index.php/restricted?key=rEsTlEr2

I think it has something to do with the .htaccess file, but i cant figure it out by myself whats wrong there. Or maybe some problem in server configuration, not sure.

Please help me to figure it out this problem.

Kind Regards,
Marius Bratu.

Unclear example

The example in CRUD are unclear to me. I could retrieve data using URL address and in which part will the DELETE, PUT, POST use to change the database data? Does it use PHP code as part of the form submission?

Support params in the form of "sort(-RowName)"

We use restler in combination with dojo and dojo provides some information (for example the name and direction of the row in a grid, that has to be sorted) in the kind mentioned in the title.
I dont know, if that is standard-REST. But maybe it should be possible to support it.

XmlFormat should not be using `htmlentities`

Restler is currently using htmlentities while creating text nodes and attribute values which is not required and will add html entities such as &aacute; which are not xml entities unless the elements are declared.

only PHP 5.4 has support for ENT_XML1 support.

PHP Warning raised with classname=methodname without prefix

Hi
Having this class and using a get request like http://localhost/rest/luracrest/app/test/test/1 this raises a php warning :
Warning: Missing argument 1 for Test::Test(), called in D:\phptools\rest\luracrest\restler\restler.php on line 341
etcetera. When i rename method 'Test' to 'getTest' or 'myTest' the warning dissapears. No big issue but perhaps it's a little bug

<?php
class Test
{
  function Test($param1)
 { 
     return "Hello Test data=$param1";
  }
}
?>

Encryption/Decryption

Hi,

It would be nice if Restler supports encryption/decryption of request/response body's. This is needed for me since there is some sensitive data going over the internet.

Thanks

UTF8 is broken by object_to_array

I found out that JSON return broken utf8 strings, I found out that the problem is inside object_to_array and utf8_encode() do the bad stuff. you can easily check output of string "mądrość" and see that using utf8_encode() returning string is broken. This is becaues using this function on string that is not iso8859-1 will do bad things.

            $value = $value; //this was broken! $value = utf8_encode($value);

Problem with swedish characters (utf8?)

I have problem to return swedish characters. i think its a utf8 problem. When i return some data from my database its just return null if it contains any "special character".

When i pass data to the server and return it then i get outputs like this "test\u00e5\u00e4\u00f6test"

multi format issue

Hi Arul

when i call http://localhost/api/v1/index.php/text/iseng.xml?api_key=ok&text=ok it will return an xml format

but why when i call http://localhost/api/v1/index.php/text/iseng.xml/api_key=ok/text=ok return is in Json Format ?

It's same if i call http://localhost/api/v1/index.php/text/iseng.xml/ok/ok

the return is in json format

I also find that that your xml format have an issue when handle an urlencode

http://localhost/api/v1/index.php/text/iseng.xml?api_key=ok&text=budi+%26+anto

won't give any result. but

http://localhost/api/v1/index.php/text/iseng.json?api_key=ok&text=budi+%26+anto

is working fine

Thanks

CRUD example

Hi,

When trying to make the CRUD examples work, I found out that the sessiondb class with a restclient (like chrome restconsole) do not work as expected. The $_SESSION is not understood in the restclient ofcourse and results are not as expected.
It's better to use a real database backend or just write results to a simple logfile. Then the CRUD works with all the VERBS, although it crashes with UTF-8 stuff. Perhaps a more detailed CRUD example and more docs will take away a lot of confusion.

Restler 3.0 Feature Requests and Ideas

Since you asked for idea's, let me start with some :-)

  1. Output structure: http://groups.google.com/group/api-craft/browse_thread/thread/9b046e863b5943df. Metadata is something that can be generated from the API it self. Links can be generated from the class the user builds.
  2. Correct header settings: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html. Think some things here can be found that are useful. Like: 14.7 Allow
  3. Pagination: limiting the returning result set. Can be build in the api class of the user self, but perhaps some core functionality can be build in the API core ?
  4. JsonP: JsonP as part of the package; JsonP becomes more and more important with cross-domain usages.
  5. Versioning Support: To have an inbuilt Restler way to manage your API versions (Request from @KitCarrau in issue #21)

More will follow when they pop up in my mind :-)

Implement $format->setMIME($mime);

Both the methods getRequestFormat and getResponseFormat call $format->setMIME($mime); after doing content type negotiation but these are just stubbed in the formats UrlEncodedFormat and JsonFormat.

<?php

    public function setMIME($mime){
        //do nothing
    }

May this be why I Accept headers were not working when I tested this?

I will gladly fix it for you if I am correct in my assumption and brief investigation but currently in the middle of something. May this issue serve as a reminder.

Keep up the good work and timely responses, you rock!

404 Not Found header always returned for HTTP HEAD request

Hello,

When I throw an exception:

    if(!$companies) {
        throw new RestException(204,"No Company Found");
    }

or return a response - the headers I receive are always

curl -I  api.local/company/1
HTTP/1.1 404 Not Found
Date: Thu, 10 Nov 2011 16:33:53 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.2
Cache-Control: no-cache, must-revalidate
Expires: 0
Content-Type: application/json

regardless of whether content is being returned. am I executing the framework right?

issues with jQuery.post

I seem to be getting 404 responses when posting to a restler handled URL via jQuery.post (same domain.)

The same URL in the browser works just fine. Any ideas?

Interfaced/Extended class not working on get without Parameter

I got a case where I want to implement the CRUD method as described in http://help.luracast.com/restler/examples/_006_crud/readme.html. Using a simple class with a method get works. If the class is defined via interface and extends another class then only the parent get method is executed.

Example:

the class itself

<?php
class Attachment extends bokaApiObject implements bokaApi {
    function get($id=NULL){
        return is_null($id); // just for proofing the point
    }
}

the parent class

<?php
class bokaApiObject {
   function __construct($dbtype=false, $dbhost=false, $dbuser=false, $dbpass=false, $dbname=false){
        // some database stuff
    }
    function get($id=NULL){
        throw new RestException(501);
    }
}

the interface

<?php
interface bokaApi {
    function get();
}

If you call /apiserver/attachment it returns a 501 exception
If you call /apiserver/attachment/someid it returns a false (for is_null() in the classes get method)

Taking extends and interface away from the class Attachment results in a working Api class.

setSupportedFormats() multi-format overridden in browser

By default browsers toggle a variety of 'Accept' headers while generating a GET request, which causes setSupportedFormats() to be overridden and set to XML (only when multiple formats are set).

Generic GET:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Code (line 537):

<?php
//...
//check if client has sent list of accepted data formats
if(isset($_SERVER['HTTP_ACCEPT'])){
    $acceptList = array();
    $accepts = explode(',', strtolower($_SERVER['HTTP_ACCEPT']));
    if (!is_array($accepts)) $accepts = array($accepts);
    foreach ($accepts as $pos => $accept) {
        $parts = explode(';q=', trim($accept));
        $type = array_shift($parts);
        $quality = count($parts) ? floatval(array_shift($parts)) : (1000 - $pos) / 1000;
        $acceptList[$type] = $quality;
    }
    arsort($acceptList);
    foreach ($acceptList as $accept => $quality) {
    if(isset($this->format_map[$accept])){
            $format = $this->format_map[$accept];
            $format = is_string($format) ? new $format: $format;
            $format->setMIME($accept);
            //echo "MIME $accept";
            header("Vary: Accept"); // Tell cache content is based on Accept header
            return $format;
        }
    }
}
//...

Proposed workaround:

<?php
//...
//check if client has sent list of accepted data formats
if(isset($_SERVER['HTTP_ACCEPT'])
   && ($_SERVER['HTTP_ACCEPT'] !== 'text/html,application/xhtml+xml,'
   . 'application/xml;q=0.9,*/*;q=0.8')){
//...

get, post, put, delete, index reserved words?

first up, i cant find any .htaccess example in the source or in the wiki. perhaps use this

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [QSA,NC,L]

ok now first up, if function get() {} is specified then function index() {} is no longer accessible. i this that makes sense but maybe one would override the other and then index still might be accessible using /index ?
anyway thats not so important.

What i have found is that functions using get in the name function getthis(){} etc do not work. If this is by design then thats ok but hope you can include it in the documentation somewhere so people know.

Parse Error Issue with ternary line 545

PHP Parse error:  syntax error, unexpected ':' in /home/dgersh/Restler/restler/restler.php on line 545
$quality = array_shift($parts) ?  : (1000 - $pos) / 1000;

Was testing on a PHP version < 5.3

What should be the proper value here? I put in null which made it stop but I haven't read enough of the code yet to see what it should be?

API Console, Documentation Explorer Support (like Swagger etc)

@Luracast , a while back you had posted that you were going to have something like swagger or swagger support for R3. Can you comment a bit more? I will be looking for something like that to help map our public API in a little while... does R2 have some form of exposing the valid resources, etc, like swagger wants (a resources.{format} file)? (I assume it wouldnt be too hard to do just looking at the routes in the restler obj...) Can you please comment about what you are doing/have done/planning exactly? Is it supporting Swagger itself? is it a swagger like tool to provide swagger-like docs and tester? (pretty API docs/console) I'm a bit lost cause swagger is a completely different server stack, java, etc, and although I suppose a restler based service could power a swagger endpoint, it would be a pain to install swagger...

Is there something else similar to swagger which is php and which is available for developers to add a console/documentation to an API? I'm going to need this soemtime soon and I'm weary of doing it all... I realize that adding some documentation with phpdoc comments is good, descriptions of methods, etc, but phpdoc doesnt accomodate example inputs jsons and outputs jsons, for example, etc (at least doesnt do it in any nice way that I have seen? I have searched for a few phpdoc api documentations and found nothing really...)

thanks!

Overriding status codes with 200 OK?

Wasnt there an example/discussion about overriding the output code with a 200 OK for header purposes?

(i.e. sending a Rest Exception 404, but having the header come out as a 200 OK?)

I thought I remembered something like this? Is this possible with a specific format or something? I am driving the frontend to a site with restler and some JS is having trouble processing some error code returns which arent 200 and getting the message... I thought for these cases I'd maybe send always a 200.. maybe add a specific extension as I didnt want to remove the error code headers completely.

Is this possible currently in R2?

thks!

CORS OPTIONS method

Cross domain requests make a preflight request first, using the OPTIONS method.
I'm not sure how to handle that, any examples?

I was getting:

OPTIONS http://mydomain/session 404 (Not Found)

So I added an options method to my Session class:

function options()
{
  return;
}

Now the error is gone, but I don't think the request is being done.

I also tried adding these headers:

header("Access-Control-Request-Method: GET, POST, OPTIONS");

But something else must be missing.

Can you provide an example?

post protection doesn't recognize key

Hi!

I tryied to protect my functions and to not send the key in the url, I decided to send the request in POST:

function post ($url,$parameters) {  
        // Get the curl session object
        $session = curl_init($url);
        // set url to post to 
        //curl_setopt($session, CURLOPT_URL,$url);
        // Tell curl to use HTTP POST;
        curl_setopt ($session, CURLOPT_POST, true);

        $parameters_key_and_value=array();
        foreach ($parameters as $key => $value) {
             $parameters_key_and_value[]=$key.'='.$value;
        }
        $parameters_url= implode('&',$parameters_key_and_value);

        // Tell curl that this is the body of the POST
        curl_setopt ($session, CURLOPT_POSTFIELDS, $parameters_url);
        // Tell curl not to return headers, but do return the response
        curl_setopt($session, CURLOPT_HEADER, false);
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        // allow redirects 
        //curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
        $result = curl_exec($session);
        curl_close($session);

        return $result;
}

Then I use my function to do my request:

$url = REST_URL.'method.json';
$parameters = array(
    'key'=>'too',
    'parameter1'=>$parameter1value
);
$result = post($url,$parameters);

Result: "Unauthorized"

Thanks

Kevin

how do i get content from what i HTTP PUT

when i use a "HTTP PUT" method to put something as json format, how do i trans my json to array ?
i try to use this

$put_data = json_decode(file_get_contents('php://input'), true);
var_dump($put_data);

then i got nothing

my function is like

// request put
function putpatients($id) {
$put_data = json_decode(file_get_contents('php://input'), true);
var_dump($put_data);
}

Typo in Examples .htaccess file

First, i'd like to say that Restler is awesome.

Second, While borrowing the code in Example 1, i noticed a typo in /examples/_001_helloworld/.htaccess on line 9, a lowercase i was used when an Uppercase I is proper, i can send in a pull request for the fix if you'd like.

debugging

hello,

What is the easiest way to debug Services? How can we see possible errors in the code of the service?

Thanks

Development Aids? (Dev, Testing/Debugging, Unit/Function Tests, Documentation)

Hi Guys,

Sorry if this is the bad place for this, just wanted to spark some friendly chatter on what you guys use for development and testing of the API (not just unit testing or valiadation testing, but also development trial-and-error "hit-refresh-till-your-finger-hurts" testing)...

Development

For development I've been using Netbeans with xdebug on the dev server... Its pretty ok, some things I wish were better, others I really like, eh... so long I hadnt used a real IDE for me its cool... I'm going to try a few others soon as see what I like best. (I wanted something multiplatform as I have a mac at home and windows in the office - purely by choice, so lets not debate this :p)... One cool thing I did is I setup a dual monitor system, so I have a browser on one screen and the IDE on another. I then made a shortcut key to switch to the browser, hit refresh (F5) and back to the IDE instantly (keyboard hotkey with autohotkey). With this I can stay in the IDE debugger and just glance to the side to see the result of the code as it executes. Saves me a lot of mouse movement and alt-tabbing (from 1 monitor)...this works great for the browser-based stuff or GET-requests in restler, which brings me to:

For Development-time testing and debugging:

I've been using mostly Firefox itself bare (GET methods mostly...) and an extension called RESTClient (https://github.com/chao/RESTClient/)... I find it pretty good and easy and quick... I can just type in a url, parameters and fire off requests in any method I require. Still trying to figure out keyboard shortcuts to refresh requests and such tho...

I have heard on the web good things of SoapUI but when I downloaded it I couldnt make it work within the first 3 minutes so I gave up (although I have it on my list to revisit as I gather its suppose to help with unit tests and such...)

Talking about Unit Tests and documented, replayable tests:

Has anyone used something such as Selenium IDE to test their APIs? I tried it very briefly but I didnt find a way for non-GET requests, so I gave it up... I think something like this would be nice to have that we can kind of record tests and then put expected returns etc... I have a hard time writing tests because I take just as long writing the test as the code, for me I feel its very inefficient... I'm definitely on the lookout for something "macro-ish" selenium ide looked cool but I couldnt firgure out the post requests...

Documentation

I've been using a bit of PHPDocs which is cool... It really wasnt something I was in much of the habit of doing... despite commenting quite a bit of my code in the past, i had never used anything to extraact the comments and build a documentation... It makes an effect on what you comment and how you comment... You write differently based on audience, and one thing is the audience inside the code you are wriitng and another is the audience outside the code, looking at a documentation.

As for API documentation we spoke about swagger on another issue and I think it is the nicest one around... I am defo waiting for R3 to start using that... (or if anyone has developed a class that mapes the Restler 2 routes into a swagger resource file that would be awesome... I'm kinda busy (semi-lazy after luracast said its coming in restler3) to write my own...

So lets hear it from you other guys.... maybe after we have some comments we can make a wiki page of useful tools...

PUT and PATCH

More of a tech discussion then a real issue.

Im busy designing my API and i've been reading up about the PATCH support and what the difference is between PUT and PATCH.

Technically wise it allows you to update a anything you want of an object with PATCH.
With PUT you need to send the whole object.

Now my question is: How to do this coding wise?

@Luracast I know you are putting PATCH support in, in what sense are you supporting it ?

Case isn't preserved in url parameters

Here is a simple example Restler program:

<?php
require('restler.php');

class Test {
    public function get($id) {
        echo $id;
        exit;
    }
}

$r = new Restler();
$r->addAPIClass('Test');
$r->handle();

The following url outputs "AbCdEf", which it should:

http://localhost/test/?id=AbCdEf

However, the following url outputs "abcdef", which is incorrect

http://localhost/test/AbCdEf

This is happening on version 2.1.7.

mod_rewriting not working

Hi,

I'am running Restler on a machine with Centos 5.1 + Apache/2.2.20 (EL) + php 5.2.17. It's working when I passed index.php in the url but it only display a blank page if I removed it?

I've have test the apache's mod_rewrite module with a simple test (redirecting to yahoo) and it's working.

Do you have clues where I can look to validate the rewrite rule and understand why is returning a blank page?

thank you in advance!

MartinO

PHP.net Style Manual

First of all, thank you so much for this great project, I'm using it to drive two of my major products right now.

One thing I noticed is that, although the live examples are great, they're not really covered in depth as a proper API documentation. I'd really like to see a sophisticated documentation provided with something like PHP.net style Manual, where official examples are exposed there and user contributions/usages can be directly given on each topic.

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.