Slide 4 - Basic RESTful API
Slide 4 - Basic RESTful API
Web
Application
Web Service
Desktop o1 o2
Consume
Application
o3 DB
Moble o4 oN
Application
Web SOAP
Web Server
Service
Communication
Data structure
FIREBASE REST API URLS
EntryPoint URLs
https://poly-java-6-d4e0b-default-rtdb.firebaseio.com/
…users.json => all users
…users/PS09013.json => one user GET POST
…users/PS09013/name.json => name
…users/PS09013/contact.json => contact PUT DELETE
…users/PS09013/contact/email.json => email
CONSUME FIREBASE REST API
EntryPoint URL = “https://.../users/PS09013.json”
Data Structure = {
“id”: “?”, Firebase
“name”: “?”, REST API
“contact”: {
“email”: “?”,
“phone”: “?”
response
}
request
}
Operations
GET: request (url) => response (user)
POST: request (url, user) => response (key)
PUT: request (url, user) => response (user)
DELETE: request (url) => response (null) REST Consumer
REST API EXCHANGE MODEL
Request:
Method: GET, POST, PUT, DELETE
URL: EntryPoint
JsonData: JSON
Response:
JsonData: JSON
(Web Browser) (Web Server)
AngularJS RestTemplate
Web Browser
Desktop App
URL, Jackson
ANGULARJS $HTTP SERVICE API
• get().then().catch() • post().then().catch()
GET POST
DELETE PUT
• delete().then().catch() • put().then().catch()
ANGULARJS $HTTP SERVICE
REST API Operations
$http.get(url).then(response => {}).catch(error => {})
$http.post(url, data).then(response => {}).catch(error => {}))
$http.put(url, data).then(response => {}).catch(error => {}))
$http.delete(url).then(response => {}).catch(error => {}))
Ví dụ
$http.get(“…/users.json”).then(response => {
var users = response.data;
})
.catch(error => {
console.log(“Lỗi”, error);
})
ANGULARJS - DEMO APPLICATION MODEL
controller
AngularJS
_form.html
$http
_table.html
JACKSON API
ObjectMapper JsonNode
readValue() get() JsonNode
readTree() findValue()
writeValue() asType()
writeValueAsString() iterator()
ObjectNode
createObjectNode() ObjectNode
put()
putObject()
putArray()
JAVA DESKTOP APPLICATION – DEMO APPLICATION MODEL
URL, Jackson
Swing JFrame
Event Handler
RESTTEMPLATE API
• getForObject() • postForObject()
GET POST
DELETE PUT
• delete() • put()
RESTTEMPLATE API
HashMap<String, User>
UserMap
User
id: String
name: String
contact: Contact
Contact
email: String
phone: String
SPRING RESTTEMPLATE – DEMO APPLICATION MODEL
RestTemplate
Controller
_form.html
_table.html
Web Browser
SUMMARY
Web Service
REST & REST API
Firebase REST API & Postman
Consume REST API with
AngularJS
Java.net.URL
RestTemplate