Create Service
Creates the specified Service Fabric service.
This api allows creating a new Service Fabric stateless or stateful service under a specified Service Fabric application. The description for creating the service includes partitioning information and optional properties for placement and load balancing. Some of the properties can later be modified using UpdateService
API.
Request
Method | Request URI |
---|---|
POST | /Applications/{applicationId}/$/GetServices/$/Create?api-version=6.0&timeout={timeout} |
Parameters
Name | Type | Required | Location |
---|---|---|---|
applicationId |
string | Yes | Path |
api-version |
string | Yes | Query |
timeout |
integer (int64) | No | Query |
ServiceDescription |
ServiceDescription | Yes | Body |
applicationId
Type: string
Required: Yes
The identity of the application. This is typically the full name of the application without the 'fabric:' URI scheme.
Starting from version 6.0, hierarchical names are delimited with the "~" character.
For example, if the application name is "fabric:/myapp/app1", the application identity would be "myapp~app1" in 6.0+ and "myapp/app1" in previous versions.
api-version
Type: string
Required: Yes
Default: 6.0
The version of the API. This parameter is required and its value must be '6.0'.
Service Fabric REST API version is based on the runtime version in which the API was introduced or was changed. Service Fabric runtime supports more than one version of the API. This is the latest supported version of the API. If a lower API version is passed, the returned response may be different from the one documented in this specification.
Additionally the runtime accept any version that is higher than the latest supported version up to the current version of the runtime. So if the latest API version is 6.0, but if the runtime is 6.1, in order to make it easier to write the clients, the runtime will accept version 6.1 for that API. However the behavior of the API will be as per the documented 6.0 version.
timeout
Type: integer (int64)
Required: No
Default: 60
InclusiveMaximum: 4294967295
InclusiveMinimum: 1
The server timeout for performing the operation in seconds. This timeout specifies the time duration that the client is willing to wait for the requested operation to complete. The default value for this parameter is 60 seconds.
ServiceDescription
Type: ServiceDescription
Required: Yes
The information necessary to create a service.
Responses
HTTP Status Code | Description | Response Schema |
---|---|---|
202 (Accepted) | A successful operation will return 202 status code. |
|
All other status codes | The detailed error response. |
FabricError |
Examples
Basic stateless service
This example shows how to create a basic stateless Service Fabric service.
Request
POST http://localhost:19080/Applications/test/$/GetServices/$/Create?api-version=6.0
Body
{
"ServiceKind": "Stateless",
"ApplicationName": "fabric:/test",
"ServiceName": "fabric:/test/test1",
"ServiceTypeName": "StatelessFrontendService",
"PartitionDescription": {
"PartitionScheme": "Singleton"
},
"InstanceCount": "4"
}
202 Response
Body
The response body is empty.
Basic stateful service
This example shows how to create a basic stateful Service Fabric service.
Request
POST http://localhost:19080/Applications/test/$/GetServices/$/Create?api-version=6.0
Body
{
"ServiceKind": "Stateful",
"ApplicationName": "fabric:/test",
"ServiceName": "fabric:/test/test2",
"ServiceTypeName": "StatefulBackendService",
"PartitionDescription": {
"PartitionScheme": "Singleton"
},
"TargetReplicaSetSize": "3",
"MinReplicaSetSize": "2",
"HasPersistedState": false
}
202 Response
Body
The response body is empty.
Stateless service with dns name and auto scaling
This example shows how to create a stateless Service Fabric service with a dns name definied and auto scaling based on cpu usage.
Request
POST http://localhost:19080/Applications/test/$/GetServices/$/Create?api-version=6.0
Body
{
"ServiceKind": "Stateless",
"ApplicationName": "fabric:/test",
"ServiceName": "fabric:/test/test1",
"ServiceTypeName": "StatelessFrontendService",
"InitializationData": [],
"PartitionDescription": {
"PartitionScheme": "Singleton"
},
"InstanceCount": "2",
"PlacementConstraints": "Color==Blue",
"CorrelationScheme": [],
"ServiceLoadMetrics": [],
"ServicePlacementPolicies": [],
"DefaultMoveCost": "Low",
"IsDefaultMoveCostSpecified": true,
"ServicePackageActivationMode": "ExclusiveProcess",
"ServiceDnsName": "test1.test",
"ScalingPolicies": [
{
"ScalingTrigger": {
"Kind": "AveragePartitionLoad",
"MetricName": "servicefabric:/_CpuCores",
"LowerLoadThreshold": "0.300000",
"UpperLoadThreshold": "0.800000",
"ScaleIntervalInSeconds": "600"
},
"ScalingMechanism": {
"Kind": "PartitionInstanceCount",
"MinInstanceCount": "1",
"MaxInstanceCount": "6",
"ScaleIncrement": "2"
}
}
]
}
202 Response
Body
The response body is empty.
Stateful service with named partitions and auto scaling
This example shows how to create a stateful Service Fabric service with named partitions and scaling enabled based on memory usage.
Request
POST http://localhost:19080/Applications/test/$/GetServices/$/Create?api-version=6.0
Body
{
"ServiceKind": "Stateful",
"ApplicationName": "fabric:/test",
"ServiceName": "fabric:/test/test2",
"ServiceTypeName": "StatefulBackendService",
"InitializationData": [],
"PartitionDescription": {
"PartitionScheme": "Named",
"Count": "1",
"Names": [
"0"
]
},
"TargetReplicaSetSize": "3",
"MinReplicaSetSize": "2",
"HasPersistedState": true,
"ServicePackageActivationMode": "ExclusiveProcess",
"ScalingPolicies": [
{
"ScalingTrigger": {
"Kind": "AverageServiceLoad",
"MetricName": "servicefabric:/_MemoryInMB",
"LowerLoadThreshold": "500",
"UpperLoadThreshold": "900",
"ScaleIntervalInSeconds": "600",
"UseOnlyPrimaryLoad": false
},
"ScalingMechanism": {
"Kind": "AddRemoveIncrementalNamedPartition",
"MinPartitionCount": "1",
"MaxPartitionCount": "3",
"ScaleIncrement": "1"
}
}
]
}
202 Response
Body
The response body is empty.