0

How to read data website 1 in website 2 with api?

- I created a php crud page (website 1)in Laravel - what should I do next? - what should add in website 1 to return json format data, cuz mine is return view(folder::file),compact('a','b','c');

12th Apr 2024, 5:58 AM
Audsay
Audsay - avatar
16 ответов
+ 2
Make sure that the endpoint you've created is accessible via a URL so that website 2 can send requests to it. You can define this route in your "routes/web.php" or "routes/api.php" file. Here's an example of how you can modify your controller function to return data in JSON format: public function getData() { $data = YourModel::all(); // Fetch your data from the database return response()->json($data); }
12th Apr 2024, 6:43 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 1
How to create the endpoint? Is it endpoint means (get,post,put,delete)
12th Apr 2024, 6:59 AM
Audsay
Audsay - avatar
+ 1
Audsay Yes, an endpoint generally refers to a specific URL or route in a web service that serves a specific purpose, such as retrieving data (GET), creating data (POST), updating data (PUT), or deleting data (DELETE). Each endpoint corresponds to a particular HTTP method and performs a specific action.
12th Apr 2024, 7:43 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 1
Yes, in order for website 1 to properly function, you need to have HTTP methods defined. HTTP methods (such as GET, POST, PUT, DELETE, etc.) are crucial for interacting with the server and accessing or manipulating resources on the website. They determine how clients can interact with the server and the actions that can be performed on resources.
13th Apr 2024, 5:15 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 1
Alright,thank you so much `нттp⁴⁰⁶
15th Apr 2024, 3:55 AM
Audsay
Audsay - avatar
0
Alright. Is it ok if I don't have http method? Or I have to create http method for website 1.
13th Apr 2024, 1:08 AM
Audsay
Audsay - avatar
0
After the http method for website 1, what should I do on the website 2? How to read data from website 1? Add file or add code?
14th Apr 2024, 12:07 AM
Audsay
Audsay - avatar
0
fetch('url of website') .then(response => response.json()) .then(data => { console.log(data); }) .catch(error => { console.error('Error fetching data:', error); });
14th Apr 2024, 2:36 AM
Vidhya Tharan
Vidhya Tharan - avatar
0
Using AJAX
14th Apr 2024, 2:37 AM
Vidhya Tharan
Vidhya Tharan - avatar
0
For the http method, can I use any method since any method is a route that responds to all http verbs
15th Apr 2024, 1:58 AM
Audsay
Audsay - avatar
0
No, definitely not. Each HTTP method has a specific purpose and behavior defined in the HTTP specification. It's important to adhere to the HTTP method semantics to ensure proper functioning, clarity, and maintainability of your API endpoints. Audsay
15th Apr 2024, 3:48 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
0
You're most welcome Audsay
15th Apr 2024, 4:13 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
0
After creating the endpoint, then the next step is to check the endpoint using postman, right?
15th Apr 2024, 4:43 AM
Audsay
Audsay - avatar
0
To pass the data to website 2, the output for website 1 needs to be printed in json format, is it?
15th Apr 2024, 4:44 AM
Audsay
Audsay - avatar
0
Yes, that is correct! After creating the API endpoint, the next step is usually to test the endpoint using a tool like Postman. Postman allows you to make HTTP requests to your API endpoint and inspect the responses, which helps in verifying that the endpoint is working as expected.
15th Apr 2024, 4:49 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
0
And yes, in order to pass the data from Website 1 to Website 2, you can format the output data from Website 1 in JSON format.
15th Apr 2024, 4:50 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar