Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

How to Call any API and Print Value ?

In this tutorial I’m going to learn how to call api and print data in blade page, so follow this tutorial i have mentioned in very easy way.

First to create one controller

php artisan make:controller PostController

Next go to controller and put below code

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class PostController extends Controller
{
    public function getallpost()
    {
      $response =  Http::get('https://jsonplaceholder.typicode.com/posts');
      return view('allpost',['data'=>$response->json()]);
    }
}

Next go to Api.php and put below code

Route::get('/getdata','PostController@getallpost');
Route::get('/singledata/{id}','PostController@getPostById');

Next to create view page allpost.blade.php and put below code.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    @foreach ($data as $item)
      <h2>{{$item['title']}}</h2>
      @endforeach
</body>
</html>



Next to create allpost.blade.php and paste below code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<h1>single page post</h1>
<h2>{{$data['title']}}</h2>
<p>{{$data['body']}}</p>
</body>
</html>

Next to run the server and see the api results.

Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.

Related Posts

How to use YouTube Video Downloader Tools ?

In this tutorial I’m going to learn how to use YouTube video download tools that developed by WizBrand Developers Team. Why Use YouTube Video Downloader Tools? Using…

How to add Enable Google Analytics API ?

What is Google Analytics API ? Google Analytics API is a set of programming interfaces that allows developers to interact with and access data from Google Analytics…

PDF encryption Tools By Wizbrand ?

What is PDF encryption tools ? The PDF Encrypt Tool employs industry-standard encryption algorithms like AES (Advanced Encryption Standard) to ensure the highest level of security. These…

What are the types of APIs and their differences?

What is APIs? API is basically a set of functions and procedures which allow one application to access the feature of other application REST is a set…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x