Docs Menu

HTTP Service [Deprecated]

중요

타사 서비스 & 푸시 알림 사용 중단

App Services의 타사 서비스 및 푸시 알림은 함수에서 외부 종속성을 사용하는 HTTP 엔드포인트를 만들기 위해 더 이상 사용되지 않습니다.

웹훅은 동작에 대한 변경 없이 HTTPS 엔드포인트로 이름이 변경되었습니다. 기존 웹훅을 마이그레이션해야 합니다.

기존 서비스는,9월까지 30 계속2025 작동합니다.

타사 서비스 및 푸시 알림은 이제 더 이상 사용되지 않으므로 App Services UI에서 기본적으로 제거되었습니다. 기존 타사 서비스 또는 푸시 알림을 관리해야 하는 경우 다음을 수행하여 구성을 UI에 다시 추가할 수 있습니다.

  • 왼쪽 탐색 메뉴의 Manage 섹션에서 App Settings을(를) 클릭합니다.

  • Temporarily Re-Enable 3rd Party Services 옆의 토글 스위치를 활성화한 다음 변경 사항을 저장합니다.

The Atlas App Services HTTP Service is a generic interface that enables you to communicate with any service that is available over HTTP, such as those that provide a REST API. This is useful when you need to use a service that does not have a custom service built-in to App Services.

You will need to provide values for the following parameters when you create an HTTP service interface:

/http_endpoints/<service name="">/config.json</service>
{
"name": "<Service Name>",
"type": "http",
"config": {}
}
Parameter
설명
Service Name
config.name

The name of this HTTP service interface. This must be unique from all other service interfaces in your application.

The HTTP service in App Services provides the following actions that you can call in 함수 and in the SDKs. Each action maps to a standard HTTP request method.

For instructions on using an HTTP service action, see Call a Service Action.

참고

You must enable a service action in a service rule before you can call it.

작업
설명

Send an HTTP GET request.

Send an HTTP POST request.

Send an HTTP PUT request.

Send an HTTP PATCH request.

Send an HTTP DELETE request.

Send an HTTP HEAD request.

참고

Convert HTTP Webhooks to Endpoints

HTTP Service webhoooks are deprecated in favor of custom HTTPS endpoints. You can automatically migrate your existing webhooks to endpoints in one-click. To learn how, see Convert Webhooks to HTTPS Endpoints.

You will need to provide values for the following parameters when you configure an HTTP incoming webhook:

You will need to provide a configuration file of the following form when you configure an HTTP incoming webhook:

http_endpoints/<service name="">/<webhook name="">/config.json</webhook></service>
{
"name": "<Webhook Name>",
"can_evaluate": { <JSON Expression> },
"run_as_authed_user": <Boolean>,
"run_as_user_id": "<App Services User ID>",
"run_as_user_id_script_source": "<Function Source Code>",
"respond_result": <Boolean>,
"fetch_custom_user_data": <Boolean>,
"create_user_on_auth": <Boolean>,
"options": {
"httpMethod": "<HTTP Method>",
"validationMethod": "<Webhook Validation Method>",
"secret": "<Webhook Secret>"
}
}
구성 값
설명
Webhook Name
name

필수입니다. 웹훅의 이름입니다.

참고

Each incoming webhook in an HTTP service interface must have a unique name.

Respond With Result
respond_result

Required. If true, App Services sends a response to the client that called the webhook. The response body will be the return value of the webhook function.

Run Webhook As
run_as_user_id
run_as_user_id_script_source

선택 사항. 웹훅이 호출될 때 웹훅 함수를 실행하는 App Services 사용자 의 ID입니다.

실행 사용자를 구성하는 방법에는 세 가지가 있습니다.

  • System : 실행 사용자는 MongoDB CRUD 및 애그리게이션 API에 대한 전체 액세스 권한을 가지며 모든 규칙 및 스키마 유효성 검사를 우회하는 시스템 사용자 입니다.

  • User Id: 함수를 실행할 특정 애플리케이션 사용자를 선택합니다.

  • Script: 실행 사용자의 id 를 반환하는 함수 를 정의합니다.

run_as_user_id 에 사용자 ID를 직접 지정하거나 웹훅 페이로드를 허용하고 run_as_user_id_script_source 에 사용자 ID를 반환하는 문자열화된 Atlas Function 를 제공할 수 있습니다. 특정 사용자 ID 또는 사용자 ID로 확인되는 함수를 지정하지 않으면 App Services 는 MongoDB CRUD 및 애그리게이션 API에 대한 전체 액세스 이 있는 시스템 사용자 로 웹훅 함수를 실행하고 모든 규칙 및 스키마 유효성 검사 를 우회합니다.

HTTP Method
options.httpMethod

The HTTP method that incoming webhook requests should use. You can configure a webhook to accept any method or specify a specific method. The following methods are supported:

  • GET

  • POST

  • PUT

  • PATCH

  • DELETE

  • HEAD

  • ANY

Request Validation
options.validationMethod

The request validation method incoming requests should use. The following validation types are supported:

Secret
options.secret

If Request Validation is enabled, this is the validation secret.

App Services automatically passes a payload document as the first argument to incoming webhook functions. In an HTTP Service incoming webhook the payload object represents an incoming HTTP request and has the following form:

{
"query": <query parameters>,
"headers": <request headers>,
"body": <request body (BSON)>
}
필드
설명

query

A document where each field corresponds to a query parameter that the external service included in the webhook URL.

예시

A request sent to a webhook URL with the query parameters someParameter=42&anotherParameter=hello would have the following query document:

"query": {
"someParameter": 42,
"anotherParameter": "hello"
}

headers

A document where each field corresponds to an HTTP header that the external service included in the webhook URL.

예시

A request sent to a webhook URL with a Content-Type: application/json header would have the following headers document:

"headers": {
"Content-Type": ["application/json"]
}

body

A BSON.Binary object encoded from the request body. You can access the request body by serializing the binary object to a string and then parsing the string to EJSON:

const body = EJSON.parse(payload.body.text())

The following webhook function inserts incoming data into a MongoDB collection and returns the insertedId in the response body.

exports = function(payload, response) {
const mongodb = context.services.get("mongodb-atlas");
const requestLogs = mongodb.db("test").collection("requestlogs");
requestLogs.insertOne({
body: EJSON.parse(payload.body.text()),
query: payload.query
}).then(result => {
response.setStatusCode(201);
response.setBody(result.insertedId);
})
};