Comments (6)
Another pattern to define product response is:
interface ProductResponse {
[string]?: number
} & ({
product: Product
} | {
products: Product[]
})
Also, we can even think of defining the interface without using union patten and simply define it as:
interface ProductResponse {
product: Product | Product[],
[string]?: number
}
But in this way the property name will no more self-explanatory, also it might be difficult to handle the response on application side.
from oms-api.
We could define a base response interface and extend it to specific responses like Product, Shipment etc
https://www.typescriptlang.org/docs/handbook/2/objects.html#extending-types
Create a basic POCs for these cases then we will conclude accordingly
from oms-api.
Concluded that we will use the pattern of generics
.
interface SuccessResponse<Type> {
list: Type[];
total: number;
groups?: number
}
from oms-api.
Explored around how success response are returned using rest api from ecoms
In initial exploration found that only the original object/array is returned without any other extra property like total, size, count etc
// For getting a list of products/orders
{
products: [{}, {}]
}
// For getting a single order/product
{
product: {}
}
In another exploration found that there is no specific key used while returning the response
// Can be accessible using response.data
// Getting a list of products/orders
[{}, {}]
// Get a single product/order
{}
In one more exploration found that, in case of retriving a single product just return a single object and for retriving a list, multiple other fields with items array is returned
// Get a single product/order
{}
// Retriving a list of products/orders
{
startIndex: 0,
pageCount: 0,
totalCount: 0,
items: [{}, {}]
}
One more pattern is identified in which for every api endpoint a separate response type is defined which extends another base response type.
For example when accessing api to get a single product, the response is ProductResponse extends BaseResponse
, when accessing api to get a list of products, the response type is ProductListResponse
extends OtherBaseResponse`.
from oms-api.
Discussed on the above points, and concluded that in case of fetching a specific record like a product/order/shipment using it's id, we will define the return type same as the request resource(product/ shipment / order), and in case when requesting a list of records for a resource we will return an array, total (optional), and groups(optional).
For the case of requesting multiple records:
interface ListResponse<T> {
list: Array<T>;
total?: number; // number of records on the server for the specific resource
groups?: number; // number of groups found when fetching the resource by grouping on a field
}
from oms-api.
Explored around the property/variable naming convention used to hold the total
and groups
value.
In case of solr, ngroups
contain the count of the total groups, and matches
contain the count of records.
In case of open search, https://opensearch.org/docs/latest/opensearch/bucket-agg/ is similar to grouped logic, and in open search
case we get doc_count
specifying the number of document in each bucket.
// Response in open search in case of buckets
"aggregations" : {
"response_codes" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "200",
"doc_count" : 12832
},
{
"key" : "404",
"doc_count" : 801
},
{
"key" : "503",
"doc_count" : 441
}
]
}
}
}
from oms-api.
Related Issues (20)
- Define a single method to clear all values when app unmounts
- Define user schema
- Add support to define primary and secondary id for products HOT 1
- Update the structure for oms-api package to store modules in a single place
- Define schema for shipment
- Unable to use resetConfig method from oms-api
- Update oms-api package product schema to return good identifications HOT 1
- Define schema for stock
- Handle Operators through enumeration
- Identify practices for handling errors HOT 1
- Update functions in oms api package to return a rejected promise in case of errors
- Use paramsSerializer available with axios to serialize params and qs npm package for stringifying the parameters.
- Define a method to prepare solr query
- Update readme instructions
- Define method to fetch stock for specific product on all facilities
- Define method to check for products stock on multiple facilities and add support to search stock using skus HOT 1
- Define support for configuring axios interceptor and emitting specific events
- Having error when the response is not an object HOT 1
- Add support to define the responseType when making a request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oms-api.