IoT - 22 - REST API
IoT - 22 - REST API
UNIV/POLTEK
DTS 2019
Internet of Things
22 REST API
digitalent.kominfo.go.id
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Topik Bahasan
• Overview
• API
• REST
• JSON
• XML
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Praktek
• Mengakses REST API Github
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
API
• Application Programming Interface is a set of routines,
protocols, and tools for building software applications.
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
REST
• REST kependekan dari REpresentational State Transfer
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
REST
• The REST architectural style describes six constraints.
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
REST API
• Generality
• Familiarity
• Scalability
• Segmentation
• Speed
• Security
• Encapsulation
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
REST API
• Berjalan di atas protokol HTTP
• Menggunakan JSON atau XML untuk mengirimkan data
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Endpoint
• Endpoint consists of root-endpoint and path.
• The root-endpoint is the starting point of the API you’re
requesting from.
• For example, the root-endpoint of Github’s API is
https://api.github.com while the root-endpoint Twitter’s
API is https://api.twitter.com.
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Endpoin
• The path determines the resource you’re requesting for.
• Think of it like an automatic answering machine that
asks you to press 1 for a service, press 2 for another
service, 3 for yet another service and so on.
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Endpoint
• You can access paths just like you can link to parts of a
website.
• For example, to get a list of all posts tagged under
“JavaScript” on Smashing Magazine, you navigate to
http://cybertrust.biz.id/tag/javascript/.
• http://cybertrust.biz.id / is the root-endpoint and
/tag/javascript is the path.
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Method
The method is the type of request you send to the server.
You can choose from these 4 types below:
• GET
• POST
• PUT
• DELETE
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Method
Method Request Meaning
This request is used to get a resource from a server. If you perform a GET request, the server looks
GET for the data you requested and sends it back to you. In other words, a GET request performs a
READ operation. This is the default request method.
This request is used to create a new resource on a server. If you perform a POST request, the
POST server creates a new entry in the database and tells you whether the creation is successful. In other
words, a POST request performs an CREATE operation.
These two requests are used to update a resource on a server. If you perform a PUT request, the
PUT server updates an entry in the database and tells you whether the update is successful. In other
words, a PUT request performs an UPDATE operation.
This request is used to delete a resource from a server. If you perform a DELETE request, the
DELETE 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.
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Header
• 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.
• Header example: "Content-Type: application/json"
• You can find a list of valid headers on MDN’s HTTP
Headers Reference.
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Body
• The body contains information you want to be sent to
the server.
• Body example: property1=value1
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Another Example
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
{ 'sensorId': 'temp1',
'Value': 25
}
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Authentication
There are two main ways to authenticate yourself:
• With a username and password (also called basic
authentication)
• With a secret token
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Secret Token
• Users should be provided with a unique API key/
identifier that allows you to track, limit, and enable
features
• An OAuth token should be used to link API keys to
accounts instead of requesting account usernames and
passwords
• Tokens help prevent misuse of the system and limit acce
ss to the control panel.
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
Praktek
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
digitalent.kominfo.go.id
LOGO
UNIV/POLTEK
IKUTI KAMI
digitalent.kominfo
digitalent.kominfo
DTS_kominfo
Digital Talent Scholarship 2019
digitalent.kominfo.go.id
digitalent.kominfo.go.id