EasyData icon indicating copy to clipboard operation
EasyData copied to clipboard

Any document about the entity CRUD restful apis

Open timiil opened this issue 3 years ago • 7 comments

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 !

timiil avatar Dec 01 '21 01:12 timiil

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

antifree avatar Dec 05 '21 17:12 antifree

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 !

timiil avatar Dec 06 '21 02:12 timiil

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.
}

korzh avatar Dec 06 '21 11:12 korzh

thanka a lot for the info

timiil avatar Dec 06 '21 14:12 timiil

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

fasteddys avatar Dec 24 '21 06:12 fasteddys

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.

korzh avatar Dec 24 '21 14:12 korzh

Hi korzh, is the API doc up now?

karasuma27 avatar Jul 28 '23 14:07 karasuma27