metarpheus-js-http-api
metarpheus-based js HTTP API
DEPRECATED use https://github.com/buildo/metarpheus-io-ts instead
License: MIT License
On a few old projects we had .fromApi
defined on MyStruct.prototype
for complex objects to be parsed from api. I think this convention is dead now, so we should remove this check
// TODO(gio): is `.fromAPI` used anywhere in our projects?
{optional: describe a possible fix for this defect, if not obvious}
{optional: other useful info}
For every api response we get, we are feeding it into returnType
, no matter what the build NODE_ENV
is.
Do we want this even in production
? What are the implications?
// TODO(gio): this is not under __DEV switch
// - why? maybe because in general, instantiating structs could be needed even in prod
// - does it have perf impacts?
{optional: describe a possible fix for this defect, if not obvious}
{optional: other useful info}
be more gentle with Uglify and copy-paste the process.env.NODE_ENV !== 'production'
switch instead of assigning to __DEV
{optional: describe a possible fix for this defect, if not obvious}
{optional: other useful info}
as per title, the return value is not used in any way anymore
possible now that metarpheus-tcomb
produces it: buildo/metarpheus-tcomb#12
add the feature in a backward compatible way
{optional: other useful info}
t.assert
checks for guard === true
but MyStruct(value)
is not a boolean :P
We are currently (implicitly) relying on the fact that whatever we are going to stringify already defines a correct toJSON
and a correct toString
.
This could be problematic since, for instance, it is true that Date.prototype.toJSON !== Date.prototype.toString
, so we would stringify a date in some way if passed as part of JSON data
(toJSON === toISOString
) and in a different way if passed as query
param (toString
)
here are the two original TODOs:
// TODO(gio): do we really need this?
// stringifyParam = value => t.match(value,
// t.Str, v => v,
// t.Date, v => v.toISOString(),
// t.Bool, v => String(v),
// t.Number, v => String(v),
// t.Nil, () => undefined, // undefined (query) params are stripped by axios down the road
// t.Any, () => {
// throw new Error('Unhandled param type', value);
// }
// );
// const query = Object.keys(qq).reduce((ac, k) => {
// return {
// ...ac,
// [k]: stringifyParam(qq[k])
// };
// }, {});
{describe the defective behavior}
{optional: describe a possible fix for this defect, if not obvious}
{optional: other useful info}
as per title, add a nice warning if this happens
{optional: other useful info}
an old (from [email protected] era) TODO said:
// TODO(gio): not sure why but the automatically inferred Content-Type
// is omitted if providing a custom transformRequest
if (['post', 'put', 'patch'].indexOf(method) !== -1) {
headers['Content-Type'] = 'application/json';
}
do we still need this with the current axios version?
Currently, in case of POST requests, wiro metarpheus apis require an empty json body ({}
) even if there are no body params in the request. The developer is thus required to call the generated api method as methodName({ data: {} })
even if there's no data to pass.
To be kinder and for consistency, we could pass this empty body automatically
data
to {}
if method is POST
PUT
requests too?See https://github.omnilab.our.buildo.io/buildo/aliniq/issues/4703
In this case, the promise was not properly rejected
as per title
{optional: describe technical specs to implement this feature, if not obvious}
{optional: other useful info}
similar to #11 , but specific to "error parsing" only
discovered in https://github.omnilab.our.buildo.io/buildo/aliniq/issues/4721
try/catch
error parsing and always return something well-formed
{optional: other useful info}
as per title (tested on qia)
it returns an undefined
status, while we typically expect an HTTP status there
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.