AxRequestService

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

ParameterDescriptionTypeDefault
urlThe endpoint URL.string
methodThe HTTP method.AxHttpMethod
bodyThe request body e.g. FormData, JSON.anynull
paramsThe 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

ParameterDescriptionTypeDefault
procedureThe procedure name.string
methodThe HTTP method. (GET, POST)'GET' | 'POST'
paramsThe parameter of procedure.any{}

Returns

Observable<T>Observable ของ HTTPResponse ด้วย response body ตามชนิดของ T ที่ request ไป


json()

ส่ง HTTPRequest และคืนค่า Observable ของผลลัพธ์

json<T>(url: string): Observable<T>

Parameters

ParameterDescriptionTypeDefault
urlThe JSON endpoint URL.string

Returns

Observable<T>Observable ของ HTTPResponse ด้วย response body ตามชนิดของ T ที่ request ไป