restler
REST client library for node.js
I'm making a REST service using Restler, however I've found that when I pass it the ñ
character, the whole parameter becomes null.
Is this because of REST or because some weird encoding that I'm missing?
Source: (StackOverflow)
I have the following folder structure.
src/
|- index.php
test/
vendor/
composer.json
composer.lock
When i want to deploy my code, I realize that i have to map the src/ directory to document root since it contains the index.php file (which btw contains some Restler code)
However, if i do that, how do i deal with the vendor/ folder that lies outside the document root?
Source: (StackOverflow)
With relative newness to AJAX, and now just starting to learn PDO, the added level of ReSTler has me completely boggled. Modeling the below code from Restler samples, I don't know how to change the output format from what PDO is returning to what Restler and Highcharts is expecting.
How do I change this code to get from the current format to the required format? (The results will generally be 5K-10K records, if that's a factor in handling the MySQL result.)
ReSTler API Code Snippet:
$sql = "SELECT ....."
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$stmt = $this->db->query($sql);
return $stmt->fetchAll();
} catch (PDOException $e) {
throw new RestException(502, 'Listing History: ' . $e->getMessage());
}
Current Output Format (includes unwanted column names):
[
{
"chart_date": "1118966400000",
"bandwidth": "10.01",
"views": "101"
},
{
"chart_date": "1119225600000",
"bandwidth": "20.02",
"views": "101"
},
Desired Output Format (numeric and without column names):
[
[
1118966400000,
10.01,
101
],
[
1119225600000,
20.02,
202
],
Edit using suggested fetch(PDO::FETCH_NUM)
:
Per the answer from @Ricardo Lohmann, I tried fetch(PDO::FETCH_NUM), which DID remove the column names, but all columns returned seem to be string, not numeric, as the data actually is, so try this, giving me the right data type - is this part of PDO to unilaterally return string?
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
$array[$x][0] = intval( $row[0] );
$array[$x][1] = intval( $row[1] );
$array[$x][2] = intval( $row[2] );
$x++;
}
return $array;
Source: (StackOverflow)
I don't understand why this code doesn't work for me
var rest = require('restler');
var getResp = function(url){
var resp ="";
rest.get(url).on('complete',function(response){
resp = response.toString();
});
return resp;
};
I am not getting the response for getResp('google.com')
Am I missing something with restler?
Source: (StackOverflow)
I’m fairly new to iOS programming, especially when it comes to webservices. I’m developing a App for academic purposes, and I need to communicate with my server, currently using AFNetworking2 and Restler/php, everything work when it comes to GET methods. But I can’t upload anything.
Been reading for hours, in github support site, stackoverflow, pretty much all examples/questions to upload images (and there are a LOT) use this line:
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://server"]];
I do have a Client class, subclass of AFHTTPSessionManager, with my sharedClient. But all examples use this AFHTTPClient with initWithURL and other classes like AFJSONRequestOperation that I can’t no longer find.
Mostly it says I should create a singleton, subclass of AFHTTPClient, but I can´t find it anywhere. Some links even send me to official github repository but it’s not available anymore.
So my question is, where can I get more info about AFHTTPClient, should I use it, can anyone point me a tutorial on how to create one or at least understand its functionality.
Cheers
Source: (StackOverflow)
I'm using Restler 3's API-Explorer which is a fork of Swagger-UI and am wondering if anyone has found an effective way of documenting/describing the response JSON object that the API returns. Obviously some of this -- in a "read between the lines" sort of way -- is available when you interactively try out the API but I'd like some way of indicating more verbosely the structure of the response. Has anyone come up with anything for this?
Source: (StackOverflow)
I would like to download a website (html) and write it to an .html file with node and restler.
https://github.com/danwrong/Restler/
Their initial example is already halfway there:
var sys = require('util'),
rest = require('./restler');
rest.get('http://google.com').on('complete', function(result) {
if (result instanceof Error) {
sys.puts('Error: ' + result.message);
this.retry(5000); // try again after 5 sec
} else {
sys.puts(result);
}
});
Instead of sys.puts(result);
, I would need to save it to a file.
I am confused if I need a Buffer
, or if I can write it directly to file.
Source: (StackOverflow)
I've created a library for sending REST requests:
var rest = require('restler');
module.exports = {
beginSession: function()
{
var options = {
method: "GET",
query: {begin_session: '1'}};
rest.get('http://countly/i', options).
on('complete', function(data, response){
console.log('Status: ' + response.statusCode);
});
}
};
The problem is that every time I use the library and the call is responded, the 'on complete' is called multiple times: 1st use of method will call 'on complete' just once, 2nd use of method will call 'on complete' twice and so on....
What Am I doing wrong?
Thanks
Jose
Source: (StackOverflow)
I am setting up a simple Google App Script to get some data from a spreadsheet to an external app. When I open the url from my browser or curl I get the proper JSON response.
See for yourself, here is the url:
https://script.google.com/macros/s/AKfycbwUqrOsqQk4rk0lY97Wl4bRsHVk6_CMVPz3hGHeyc3H2ZCahCIY/exec
You should get a JSON response. I would like to have a node app make a request to that URL and parse the JSON response. I am attempting with two different clients, restler and request, and with both I get this error:
Error: 140735264762208:error:0607907F:digital envelope routines:EVP_PKEY_get1_RSA:expecting an rsa
key:../deps/openssl/openssl/crypto/evp/p_lib.c:288
Any recommendations?
Source: (StackOverflow)
I have been testing some PHP scripts that uses the aws-sdk-php to upload files to S3 storage. These scripts seems to work nicely when they are executed directly from the browser, but fails when trying to use it through an API class in Luracast Restler 3.0
A sample script that upload some dummy file is like the following:
<?php
require_once (dirname(__FILE__) . "/../lib/aws/aws.phar");
use Aws\Common\Aws;
use Aws\S3\Enum\CannedAcl;
use Aws\S3\Exception\S3Exception;
use Aws\Common\Enum\Region;
function test(){
// Instantiate an S3 client
$s3 = Aws::factory(array(
'key' => 'key',
'secret' => 'secret',
'region' => Region::EU_WEST_1
))->get('s3');
try {
$s3->putObject(array(
'Bucket' => 'my-bucket',
'Key' => '/test/test.txt',
'Body' => 'example file uploaded from php!',
'ACL' => CannedAcl::PUBLIC_READ
));
} catch (S3Exception $e) {
echo "There was an error uploading the file.\n";
}
}
This script is placed in the folder /util/test.php, while the aws-php-sdk is at /lib/aws/aws.phar
To test that this test method is well written I have created another php script at /test/upload.php with the following code:
<?php
require_once (dirname(__FILE__) . '/../util/test.php');
test();
So I can enter in the browser http://mydomain.com/test/upload.php and all is working as expected and the file is uploaded in S3 storage.
However when I call the function test() from an API class with the Restler framework, I have an error that says that Aws cannot be found:
Fatal error: Class 'Aws\Common\Aws' not found in /var/app/current/util/test.php on line 12
However the code is exactly the same that perfectly works when called from upload.php. I have been wasting hours trying to figure out what is happening here, but I cannot get any conclusion. Is like the aws-php-sdk autoloader does not work well under some circumstances.
Any hints?
Source: (StackOverflow)
Is it possible to do pass along arguments to an API class for the sake of constructor injection? For example, in index.php I have the following:
$r->addAPIClass('Contacts', '');
And Contacts.php looks something like this:
class Contacts
{
private $v;
public function __construct(Validation v)
{
$this->v = v;
}
}
How would I do this with Restler?
Source: (StackOverflow)
I'm trying to send a header response back from our api with a http status code 201 Created and a Location:header.
No matter what I do I get a response body too, something that I don't want.
If I return an empty string (return "";), restler will put the string '""' in the response body. If I return null or do not return anything at all restler will put the string 'null' in the response body.
How do I tell Restler to not send anything but headers?
Source: (StackOverflow)
I am pretty new to the restler. I want to obtain the html contents from a webpage. Could somebody provide some examples? Thanks a lot.
Source: (StackOverflow)
I am trying to create a plugin for making an API server for Oxwall framework. I am new to Restler but experienced developer for Oxwall platform.
I get the below error when I access the url.
{
"error": {
"code": 404,
"message": "Not Found"
},
"debug": {
"source": "Routes.php:383 at route stage",
"stages": {
"success": [
"get"
],
"failure": [
"route",
"negotiate",
"message"
]
}
}
}
Oxwall has its own Routing and MVC methods. Below is how I have defined the route (cmd is just a dummy value to make Oxwall consider it valid for say/* routes)
OW::getRouter()->addRoute(new OW_Route('service', 'say/:cmd', "OXWALLAPI_CTRL_Api", 'index'));
So now, when I try to access http://www.mysite.com/say/hello it get the above 404 error.
api.php :
use Luracast\Restler\Restler;
class OXWALLAPI_CTRL_Api extends OW_ActionController {
public function __construct() {
parent::__construct();
$r = new Restler();
$r->addAPIClass('Say');
$r->handle();
}
public function index() {
}
}
Say.php:
class Say {
function hello($to = 'world') {
return "Hello $to!";
}
function hi($to) {
return "Hi $to!";
}
}
Oxwall has its own .htaccess file. I have placed the below .htaccess in the plugin folder.
Options -MultiViews
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
php_flag display_errors Off
</IfModule>
Source: (StackOverflow)
I want to create a website on Google Cloud (Google App Engine GAE based Joomla and Restler RESTful API Server) with sub domains:
http:// api.restlerongooglecloud .com for hybrid app (based on Restler API serving smart phones like Android, iOS, Windows Phone)
and
blog: http:// joomla.restlerongooglecloud .com (Joomla blog on GAE Launcher is working nicely, I followed the guide at this link: http:// forum.joomla .org/viewtopic.php?f=706&t=828565&p=3114492 )
and
http:// www.restlerongooglecloud .com for main page.
Before I upload live site to GAE Cloud I tried to test if Restler is working fine with Google App Launcher.
The directory structure is
GAEproject-root /api/... for Restler 3.0 RC3
GAEproject-root /joomla/ for blog
GAEproject-root / app.yaml
My app.yaml is as follows:
application: restlerongae
version: 1
runtime: php
api_version: 1
handlers:
## api images
- url: /api/(.*\.(ico$|jpg$|png$|gif$))
static_files: api/\1
upload: api/(.*\.(ico$|jpg$|png$|gif$))
application_readable: true
## api html
- url: /api/(.*\.(htm$|html$|css$|js$))
static_files: api/\1
upload: api/(.*\.(htm$|html$|css$|js$))
application_readable: true
## api test1
- url: /api/(.*)
script: api/public/examples/_001_helloworld/index.php
When I run the website and point to Restler 3.0 RC5 example:
http:// localhost /api/public/examples/_001_helloworld/say/hello
I get following error:
{ "error": { "code": 404, "message": "Not Found" }, "debug": { "source": "Routes.php:359 at route stage", "stages": { "success": [ "get" ], "failure": [ "route", "negotiate", "message" ] } } }
I tried to figure out why this error, but unfortunately I am not successful and new to object oriented PHP and Restler.
Please help, how do I fix this error.
As GAE does not use ".htaccess " file or Apache, how to model "the Aapache mod_rewrite feature" using "mod_rewrite.php" Please see more details here: https:// developers.google .com/appengine/docs/php/config/mod_rewrite
Further:
Writing to local files is not supported in App Engine due to the distributed nature of your application. Instead, data which must be persisted should be stored in the distributed datastore. For more information see the documentation on the runtime sandbox
An App Engine application cannot:
write to the filesystem. Applications must use the App Engine datastore for storing persistent data. Reading from the filesystem is allowed, and all application files uploaded with the application are available.
open a socket or access another host directly. An application can use the App Engine URL fetch service to make HTTP and HTTPS requests to other hosts on ports 80 and 443, respectively.
spawn a sub-process or thread. A web request to an application must be handled in a single process within a few seconds. Processes that take a very long time to respond are terminated to avoid overloading the web server.
make other kinds of system calls.
GAE provides a stream wrapper for Google Cloud Storage which makes using the service very simple. Assuming you have completed the prerequisites files on GCS may be accessed using standard PHP file handling functions as shown in the documentation.
$contents = file_get_contents($file);
var_dump($contents); // prints: hello world
?>
I think the code in HumanReadableCache.php needs to be changed to use gs://bucket/file for cache implementation. (apiVersionMap AUTO GENERATED FILE ) I am not really a OOP_PHP programmer to replace/edit code in HumanReadableCache.php so could you please help and to come up with GAE version of Restler? Thanks a lot.
Source: (StackOverflow)