การใช้ ionic เรียก WebApi เป็น Object

1. สร้างโปรเจ็กส์ ASP.NET Core

สร้างโปรเจ็กส์แบบ ASP.NET Core WebAPI in Azure

Startup.cs

ValuesController.cs

2. สร้างโปรเจ็กส์ ionic

สร้างโปรเจ็กส์ ionic เรียกใช้ HTTP แบบ Native (GET)

home.html

home.ts

3. ผลการรัน

ลองใช้ Postman ทำการ POST

[code]
{
"ID": 101,
"FirstName": "Phaisarn",
"LastName": "Sutheebanjard"
}
[/code]

ได้ผลลัพธ์กลับมาเป็น

[code]
101 : Phaisarn Sutheebanjard
[/code]

เรียกผ่าน browser แบบ Get

ไปที่ http://jackwebapi25610824112107.azurewebsites.net/api/values/1

ได้ผลลัพธ์กลับมาเป็น

[code]
{"id":50,"firstName":"Phaisarn","lastName":"Sutheebanjard"}
[/code]

ใช้ ionic เรียกแบบ Get

[code]
http://jackwebapi25610824112107.azurewebsites.net/api/values/1
this.stStatus 200
this.stValue {"id":50,"firstName":"Phaisarn","lastName":"Sutheebanjard"}
person[‘id’] 50
person[‘firstName’] Phaisarn
person[‘lastName’] Sutheebanjard
[/code]

ใช้ ionic เรียกแบบ Post

[code]
this.stStatus 200
this.stValue 101 : Phaisarn Sutheebanjard
[/code]