0% found this document useful (0 votes)
9 views16 pages

Chapter 7

Uploaded by

Nurul Syaheera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views16 pages

Chapter 7

Uploaded by

Nurul Syaheera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

BENR2423

Chapter 7:

Database and RESTful API

Cloud System
• A communications protocol for transmitting
hypermedia documents, such as HTML.
• Designed for communication between web
browsers and web servers.
GET /index.html HTTP/1.1
Host: www.google.com
Browser Web Server

HTTP/1.1 200 OK
Content-Type: text/html

<html><head>…

Hypertext Transfer Protocol (HTTP)


• Basic HTTP request methods (HTTP verbs)
• GET
• POST
• DELETE
• PATCH
• PUT
• CONNECT
• OPTION
• TRACE

Hypertext Transfer Protocol (HTTP)


• A style of software architecture and approach to
communications often used in web services
development
• A Web service that follows these guidelines is
called RESTful
GET /index.html HTTP/1.1
Host: www.google.com
Browser Web Server

HTTP/1.1 200 OK
Content-Type: text/html

<html><head>…

Representational State Transfer (REST)


• A Web service must provide its Web resources in a textual
representation
• The Web resources should be linked to a specific URL
• Each URL is called a request while the data sent back to you
is called a response
request
GET /index.html HTTP/1.1
Host: www.google.com
Browser Web Server

HTTP/1.1 200 OK
Content-Type: text/html

<html><head>…
response

Representational State Transfer (REST)


• The Anatomy of A Request
• The endpoint : www.google.com
• The method
• The headers
• The data (or body)

GET /index.html HTTP/1.1


Host: www.google.com
Browser Web Server

HTTP/1.1 200 OK
Content-Type: text/html

<html><head>…

Representational State Transfer (REST)


• REST uses URI to identify resources
• http://portalfkekk.utem.edu.my/web/index.php?search=utem
• http://portalfkekk.utem.edu.my/web/index.php/deans-welcome-
note/
• http://portalfkekk.utem.edu.my/web/index.php/prospective-
students/programme-offered/benr/

The Endpoint
• The methods provide meaning for the request to
perform four basic actions: Create, Read, Update
and Delete (CRUD):
• GET : Read Request
• POST : Create Request
• DELETE : Delete Request
• PATCH : Update Request

The Method (HTTP Verbs)


• This is the default request method to get a resource
from a server.
• If you perform a GET request, the server looks for
the data you requested and sends it back to you.
• In general, a GET request performs a READ
operation.

GET http://benr2423.com/books
Retrieve all books

HTTP GET
• This request is used to create a new resource on a
server.
• If you perform a POST request, the server creates a
new entry in the database and tells you whether the
creation is successful.
• In general, a POST request performs an CREATE
operation.

POST http://benr2423.com/student
body: { name: 'Soo', matric: 'B0201110011’}
Create a new student

HTTP POST
• This request is used to update a resource on a server.
• If you perform a PATCH request, the server updates an
entry in the database and tells you whether the update
is successful.
• In general, a PATCH request performs an UPDATE
operation.

PATCH http://benr2423.com/student/B0201110011
body: { name: 'Soo YG', matric: 'B0201110011'}
Update student info with matric B0201110011

HTTP PATCH
• This request is used to delete a resource from a
server.
• If you perform a DELETE request, the server deletes
an entry in the database and tells you whether the
deletion is successful.
• In other words, a DELETE request performs a
DELETE operation.

DELETE http://benr2423.com/student/B0201110011
Delete student with matric B0201110011

HTTP DELETE
• Headers are used to provide information to both
the client and server.
• It can be used for many purposes, such as
authentication and providing information about the
body content.
• References:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

The Headers
• The data (sometimes called body or message)
contains information you want to be sent to the
server.
• This option is only used with POST, PATCH or
DELETE requests

The Data (Or Body)


• An API is an application programming interface. It
is a set of rules that allow programs to talk to each
other
• Developer creates the API on the server and allows
the client to talk to it

REST API
• HTTP status codes let you tell the status of the
response quickly.
• The range from 100+ to 500+. In general, the
numbers follow the following rules:
• 200+ means the request has succeeded.
• 300+ means the request is redirected to another URL
• 400+ means an error that originates from the client has
occurred
• 500+ means an error that originates from the server has
occurred

HTTP Status Codes And Error Messages

You might also like