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');
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);
}
+ 1
How to create the endpoint? Is it endpoint means (get,post,put,delete)
+ 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.
+ 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.
+ 1
Alright,thank you so much `нттp⁴⁰⁶
0
Alright. Is it ok if I don't have http method? Or I have to create http method for website 1.
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?
0
fetch('url of website')
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error fetching data:', error);
});
0
Using AJAX
0
For the http method, can I use any method since any method is a route that responds to all http verbs
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
0
You're most welcome Audsay
0
After creating the endpoint, then the next step is to check the endpoint using postman, right?
0
To pass the data to website 2, the output for website 1 needs to be printed in json format, is it?
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.
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.