Create
Endpoint POST /<plural-segment>
Where <plural-segment> is the pluralized name of your domain class, e.g., for the class Sloth, the endpoint would be POST /sloths.
Refer to the Endpoint segments section for information on changing the way the plural segment name is generated for your API types. By default, the pluralization follows standard English rules.
Response Codes
- 201 Created: Returns the key property type of the newly created object.
- 400 Bad Request: Returns a
BadRequestResultif the request is invalid.
On 201 Created, the Location header points to the created resource details path in the format /{segment}/{id}.
The {segment} value comes from IApiSegmentProvider.
Request Parameters
The Create endpoint accepts parameters based on the constructor parameters of your domain class, excluding the key parameter (for example id).
Example: If your domain class Sloth has the following constructor:
public Sloth(Guid id, string name, int age)
{
Id = id;
Name = name;
Age = age;
}
The endpoint will accept a JSON object with name and age fields.
Nested Objects: If your class contains a nested object and you wish to add it, you should specify the field representing the identifier of that nested object, e.g., YourNestedObjectId.
Return Value: The endpoint returns the identifier of the newly created object.
The key value is generated by IEntityPropertyKeyValueProvider<TEntity>.
For entities where the first constructor argument is the key (for example id), the generated key is used by the service as the source of truth.
The key value should not be sent in the request body. It is generated server-side by the configured key provider.
Refer to the Constructors section for information on specifying a particular constructor. By default, the first constructor with parameters is used.
Example Domain Class:
public class Sloth : ISlothfulEntity
{
public Guid Id { get; private set; }
public string Name { get; private set; }
public int Age { get; private set; }
public string DisplayName => Name;
public Sloth(Guid id, string name, int age)
{
Id = id;
Name = name;
Age = age;
}
public void Update(string name, int age)
{
Name = name;
Age = age;
}
}
Generated Endpoint:
POST /sloths
Response Codes:
- 201
- 400
Request Parameters:
- Body:
{
"name": "string",
"age": "integer"
}
Return Value:
"guid-of-new-sloth"