EasyData
EasyData copied to clipboard
Any document about the entity CRUD restful apis
hi, as the title say, for now, i can find is :
private static readonly Endpoint[] _routing =
{
new Endpoint(DataAction.GetModel, @"^/models/([^/]+?)$", "GET"),
new Endpoint(DataAction.GetEntities, @"^/models/([^/]+?)/crud/([^/]+?)/fetch$", "POST"),
new Endpoint(DataAction.GetEntity, @"^/models/([^/]+?)/crud/([^/]+?)/fetch/([^/]+?)$", "GET"),
new Endpoint(DataAction.CreateEntity, @"^/models/([^/]+?)/crud/([^/]+?)/create$", "POST"),
new Endpoint(DataAction.UpdateEntity,@"^/models/([^/]+?)/crud/([^/]+?)/update/([^/]+?)$", "POST"),
new Endpoint(DataAction.DeleteEntity, @"^/models/([^/]+?)/crud/([^/]+?)/delete/([^/]+?)$", "POST")
};
...
public virtual async Task HandleGetEntitiesAsync(string modelId, string entityContainer, CancellationToken ct = default)
{
int? offset = null;
int? fetch = null;
bool isLookup = false;
IEnumerable<EasyFilter> filters = null;
bool needTotal = false;
JObject requestParams;
using (var requestReader = new HttpRequestStreamReader(HttpContext.Request.Body, Encoding.UTF8))
using (var jsonReader = new JsonTextReader(requestReader)) {
requestParams = await JObject.LoadAsync(jsonReader, ct);
}
if (requestParams.TryGetValue("offset", out var value)) {
offset = value.ToObject<int?>();
}
if (requestParams.TryGetValue("limit", out value)) {
fetch = value.ToObject<int?>();
}
if (requestParams.TryGetValue("needTotal", out value)) {
needTotal = value.ToObject<bool>();
}
if (requestParams.TryGetValue("lookup", out value)) {
isLookup = value.ToObject<bool>();
}
if (requestParams.TryGetValue("filters", out value) && value.HasValues) {
filters = await GetFiltersAsync(modelId, (JArray)value, ct);
}
long? total = null;
if (needTotal) {
total = await Manager.GetTotalEntitiesAsync(modelId, entityContainer, filters, isLookup, ct);
}
var sorters = await Manager.GetDefaultSortersAsync(modelId, entityContainer);
var result = await Manager.GetEntitiesAsync(modelId, entityContainer, filters, sorters, isLookup, offset, fetch);
await WriteOkJsonResponseAsync(HttpContext, async (jsonWriter, cancellationToken) => {
await WriteGetEntitiesResponseAsync(jsonWriter, result, total, cancellationToken);
}, ct);
}
any detail documentation about these above apis ?
thanks very much !
Unfortunately, we don't have any documentation yet.
Currently, you can figure it out by observing (with the Developer Tools panel in your browser) the requests sent from the client-side to the backend in any of our sample projects.
We will let you know when we publish the docs about the API
the most complex is the 'GetEntities' action, i can not figurate out ...
curl -X POST \
http://localhost:5285/api/easydata/models/__default/crud/Store/fetch \
-H 'Content-Type: application/json' \
-d '{
"filters":[
{"class":"Store"},{"StoreId":"1525"}
]
}
the result is :
{
"result": "error",
"message": "Value cannot be null. (Parameter 'key')"
}
any quick help to this endpoint? thanks you very much !
fetch
is a POST request that has the following structure of a payload:
{
limit: <number of records to fetch in this "chunk">,
offset: <the row number we should start from>,
needTotal: true|false, //should the server-side calculate the total number of records as well
lookup: true|false, //indicates whether this is a request for "lookup" data (for example we as for the list of customers while editing an order
filters?: [ <filter1>, <filter2>, ... ]
}
Here each filter
is an object with 2 properties:
{
class: '__substring', //The type of the filter. Only "__substring" type is supported for now
value: 'any string value', //The value of the filter. In this case, the substring we filter our result set by.
}
thanka a lot for the info
Please add some documentation also on the understanding on how its logic is working` so we can use it and adapt it into the solution correctly.
If possible include a picture on the components and what pieces/where to integrate inside the solution. I think this will help many developers for you
Please add some documentation also on the understanding on how its logic is working` so we can use it and adapt it into the solution correctly.
We are going to release version 1.4.0 soon. There will be a few changes in the API. After that, we plan to publish the documentation for the library with an API reference and a detailed description of how things work.
Hi korzh, is the API doc up now?