how to call route like new request - laravel

I try to call my own api with laravel I tried all the options like:
in the answers:
Consuming my own Laravel API
or in this blog:
http://blog.antoine-augusti.fr/2014/04/laravel-calling-your-api/
and this plugin:
https://github.com/teepluss/laravel4-hmvc
sorry for sound dumb I dont understand all the things but they not make full 100% real request like
for example with normal ajax post request i can do this to get some parameter:
Request::createFromGlobals()->request->get('some-parameter')
but with the others techniqe this just return null
I am using this way becase thats the way how "thephpleague/oauth2-server" plugin get the post parametrs
( https://github.com/thephpleague/oauth2-server/blob/master/src/AuthorizationServer.php#L234 )
so my question: is there a real way to call other route and to make it 100% look like normal request?

From what it sounds like you are trying to do you could use Snoopy or cURL to make actual calls.
The real question is why do these need to be actual calls? The first link you posted has some really great examples that would work well for any calls that go directly back to your Laravel application. That article linked to a module called HMVC which keeps your code looking neat and simplifies the process.

Any HTTP Client will do this.
Guzzle
Buzz
Requests

Related

hyperledger composer: Calling a REST API (GET) from Transaction Processor Functions

Would like to make a GET call out of a transaction processor functions.
Found docu how to make a post call here: https://hyperledger.github.io/composer/integrating/call-out.html, but nothing about making a GET call.
Any idea appreciated, thanks!
Unfortunately, there isn't any way at present to do a GET. As the link you provide suggests the POST is an experimental feature and we would welcome feedback suggestions so raising a git issue at https://github.com/hyperledger/composer would be good way to provide feedback, suggestions and use cases/

Executing controllers methods from a library in codeigniter

i have a question, i am developing a library for Codeigniter to create Job Queues with workers and delayed queue (Codeigniter-JobQueue). But i have a question...
... How can i perform or execute controller's methods inside this library? It will be awesome to know this.
The library is taking "controller, method, params" to transform after to "http://www.example.com/controller/method/params".
Thanks, and if you want to help me to develop, you are welcome. ;)
Use curl. If you however expect a return variable from controllers method, then C in your MVC is not designed properly.
Curl is a way to go. Controllers should output content and not return a variable. If you are scheduling any job, the library should call the URL itself. You could use the cli mode of codeigniter.
http://ellislab.com/codeigniter/user-guide/general/cli.html

How can I generate an API Key in My own Controller in Codeigniter

Just want to mention that I am really a newbie in API development (concepts, structure, best practices) I am not nearly familiar with it at all, so please excuse my pathetic stupid question if you find it to be, I'm using Phil Sturgeon's REST API server, Curl Library, and REST API client here's my code:
in my controller application/controllers/make_key
function index(){
$this->load->library('rest');
$this->load->library('curl');
$this->rest->put('https://www.myapplication.com/apifolder/key/X-API-KEY/FOO');
}
- no response at all
where apifolder/key is the location of my key.php (from Phil Sturgeon's default example):
and note that I've also tried this via address bar:
https://www.myapplication.com/apifolder/key/X-API-KEY/FOO
- returns ({"status":false,"error":"Invalid API Key."})
https://www.myapplication.com/apifolder/key?X-API-KEY=FOO
- returns ({"status":false,"error":"Unknown method."})
and tried quite a lot more queries but none seem to be working, my only question is...
How can make this key.php work? my apologies for such a simple minded question thank you in advance
see my self-accepted answer on my own qeuestion... Phils documentation does not provide this information. I had to dig into the library myself.
i ended up finding out the 403 forbidden was because i was not providing an api key to generate keys..
Kind of abiguous as Phil's documentation doesn't state that an existing api key is required before you can generate keys..
I simply created a bogus key in the table in the db and referenced that when calling /key/index?X-API-KEY=boguskey
CodeIgniter REST API Library Ajax PUT throwing 403 Forbidden

Call a controller's method from an external ruby script

I'm creating an external service of my rails app. This is always listening a rabbitmq queue and all their messages should be redirected to some methods of the rails controllers.
I've tried these approaches:
AMQP subscriber inside Rails app
What's the correct way to run one controller action from another controller action without an HTTP redirect?
http://www.misuse.org/science/2007/07/24/firing-rails-controller-actions-from-command-line-console/
The first one allowed me only to access the model (Anyway I suppose must be the base for what I want). The second one... never worked for me. And the last one doesn't works on rails 3 ( ActionController::Integration doesn't exists)
I think that the last approach still could be used if I figure out how the sessions are handled in rails 3. In any case, somebody had tried something similar before? Any suggestion will be appreciated.
Why not just send the request via an HTTP request? Your controller basically makes actions visible via URLs - simply making a request to the URL is essentially the same as calling the controller code, and it keeps your code working like a software service/API. You could even just use curl to do this if you want.
Otherwise, if the two files are in the same machine/folder, you could try to explicitly include the one controller code in the other, but that seems like maybe not the way to go. Depends on how you want the end result to work.

Cross domain content usage from client script (security issues)

I'm trying to load some external content using jQuery load function to div on my page. load method works ok, with local content, but if you want something out of your domain, it won't work.
$("#result").load("http://extrnal.com/page.htm #data);
(it actually works in IE with security warning, but refuses to work in Chrome at all). jQuery documentation says that it is right, because cross-domain content is restricted because of security reasons. Same warning I get if use .getJSON method.
OK, after a googling a bit I found very interesting approach of using YQL for loading content, I've tried some examples, like this:
var request = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3Dyhoo%22&format=json&diagnostics=true&callback=?";
$.getJSON(request, function (json) {
alert(json);
}
);
And it really works!
What I dont understand now is that http://query.yahooapis.com is also cross-domain resouce but browser (both IE and Chrome) works OK with that?
Whats the difference? What am I missing?
Thank you
The results you are getting back from YQL are in JSON format which is permitted for cross site AJAX calls like this. Its the same mechanism that allows you to communicate with web services for external sites via JSON (Ie. the twitter API).
Details here - http://www.wait-till-i.com/2010/01/10/loading-external-content-with-ajax-using-jquery-and-yql/
you can make on external site JSON like this:
callback({key:value,etc:1})
and define
function callback(json) {
..here is processing..
}
Thanks for your answers, but unfortunately both of them do not answer my orginal question..
I've checked out related questions on stackoverflow (i know i need to do that first) and found the reason of such behavior.
First code snipset uses AJAX/JSON to retrive the data and it is permitted because of Same Origin Policy. But request to YQL uses JSONP instead, that is OK.
The JSONP was something that I don't know about, that's why I didn't undrestand the behaviour.
Introduction info on JSONP could be found here:
http://ajaxian.com/archives/jsonp-json-with-padding

Resources