Does anyone have any experience in Laravel PHP?

3    21 Jul 2015 17:14 by u/Farrarzard

Hello, I am new to Laravel and web programming in general. I've reached a point in my current project where I need to make a RESTful API call, but I can't seem to find a well-documented way to do it. Does anyone have any suggestions on tools/methods? I've already been to stackoverflow and I can't find much useful information. I know there must be a way to do it, but I can't seem to figure it out.

Thanks in advance.

6 comments

0

Are you making a RESTful API call on the server, or on the client? If it's the server, most of the time, you can just use cURL. See this Stackoverflow answer as well.

0

I intend to make the call on the client side. I have read a bit about GuzzleHttp, which seems like the best way to do it, but it just seems like there should be a way to do it with Laravel only.

0

REST API calls are basically just HTTP requests- Guzzle is (I think?) a more PHP friendly OO style way of doing HTTP requests, which is what cURL would do for you as well.

Inside of Laravel, you should be able to just roll a basic cURL request to your API.

0

That's what I ended up doing, I just needed some help figuring out where to put the code and how to access it. My buddy helped with that. Thanks!

0

What are you scripting in? Python has an awesome package called Requests that makes REST calls a breeze. My comment history is beginning to look like I wrote the package or something...I LOVE Requests, I can't help it. It's so easy.

import requests
url = 'your url here'
header = { 'apitoken' : 'your api token here','maybesomethingelseintheheader' : 'whatever the value is' }
r = requests.get(url,headers=header)
r.status() // this gives you the status code - 200 is good!
r.text // this dumps all of the return data
r.json() // this automatically decodes the json response
0

I'm using Laravel PHP, which is php-based.