againPHP LAB
againPHP LAB
PRATICAL FILE
FOR
Creating a webform
<html>
<head>
<title>Registration Form</title>
</head>
<body>
</p>
First name:
<br>
</form>
</body>
</html>
Result: Created a web form using HTTP GET and POST method.
Experiment No. 4
Object: Create PHP code that utilizes the commonly used API library functions built in
to PHP.
Theory: The full name of the API is Application Programming Interface. An API is a
set of
programming code that helps to communicate between two different software programs.
Many library
functions are used in the API, of which the most common library function is:
Requests: Requests are a library function that helps in issuing HttpRequests. Using the
Requests library it tells us what action we are going to perform by calling the API. A
total of four types of actions are performed in the Requests library is:
GET: This is the most common request method. Using this, we can get the data that we
want from the APL
POST: You can add new data to the server using this request method.
PUT: Using this request method, you can change the information present in the server.
DELETE: Using this request method, we can delete the information present in the
server which does not work in the server.
Programming:
var_dump($request->status_code); // int(200)
Use this PHP code library GET POST, PUT and DELETE HTTP Request send.
<body>
<p>Write your requests in the script and watch the console and network logs.</p>
<script>
fetch('https://jsonplaceholder.typicode.com/todos')
// GET retrieves the to-do with specific URI (in this case id = 5)
fetch('https://jsonplaceholder.typicode.com/todos/5')
"userld": 1,
"id": 5,
"completed": false
fetch('https://jsonplaceholder.typicode.com/todos', {
method: 'POST',
body: JSON.stringify({
Web Devlopement Using
userld: 1,
completed: false
}),
headers: {
})
/* will return
"userld": 1,
"completed": false,
"id": 201
fetch('https://jsonplaceholder.typicode.com/todos/5', {
method: 'PUT',
body: JSON.stringify({
userld: 1,
id: 5,
completed: false
1), headers: {
})
/* will return
"userId": 1,
"id": 5,
"completed": false
*/
fetch('https://jsonplaceholder.typicode.com/todos/1', {
method: 'DELETE'
})
// empty response: {}
</script>
</body>
</html>
Result: Thus created a first code that used the common library function requests.