AxRequestService
เซอร์วิสสำหรับดึงข่อมูลจาก API ด้วย HTTP request
When To Use
- ใช้เมื่อต้องการดึงข้อมูลจาก API ด้วย HTTP request
- ใช้เมื่อต้องการเรียก stored procedure ที่อยู่ใน database ด้วย HTTP request
import { AxHttpServiceModule } from '@atlasx/core/http-service'Example
import { AxRequestService } from '@atlasx/core/http-service'@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
constructor(private requestService: AxRequestService) {}
ngOnInit() {
this.requestService.get('https://portal-atlasx.cdg.co.th/axws-demo/api/appconfig').subscribe(
(data) => {
console.log(data)
},
(error) => {
console.log(error)
}
)
}
}Methods
request()
เรียก HTTPRequest และคืนค่า Observable ของผลลัพธ์
request<T>(
url: string,
method: AxHttpMethod,
body: any | null = null,
params: any = {}
): Observable<T>Parameters
| Parameter | Description | Type | Default |
|---|---|---|---|
| url | The endpoint URL. | string | – |
| method | The HTTP method. | AxHttpMethod | – |
| body | The request body e.g. FormData, JSON. | any | null |
| params | The HTTP params to send with the request. | any | {} |
Returns
Observable<T>: Observable ของ HTTPResponse ด้วย response body ตามชนิดของ T ที่ request ไป
sp()
ส่ง HTTPRequest พร้อมแนบพารามิเตอร์ของ stored procedure และคืนค่า Observable ของผลลัพธ์
sp<T>(
procedure: string,
method: 'GET' | 'POST'
params: any = {}
): Observable<T>Parameters
| Parameter | Description | Type | Default |
|---|---|---|---|
| procedure | The procedure name. | string | – |
| method | The HTTP method. (GET, POST) | 'GET' | 'POST' | – |
| params | The parameter of procedure. | any | {} |
Returns
Observable<T>: Observable ของ HTTPResponse ด้วย response body ตามชนิดของ T ที่ request ไป
json()
ส่ง HTTPRequest และคืนค่า Observable ของผลลัพธ์
json<T>(url: string): Observable<T>Parameters
| Parameter | Description | Type | Default |
|---|---|---|---|
| url | The JSON endpoint URL. | string | – |
Returns
Observable<T>: Observable ของ HTTPResponse ด้วย response body ตามชนิดของ T ที่ request ไป