Comments (18)
@caiobiodere no need to say sorry 😃 We all are non native speakers. You're welcome.
Before start coding a rough scribble of pseudo code might help me to understand your requirements. Maybe what you try to achieve is already possible, not sure.
Please just explain it here in a few more sentences and a sketch.
from pretend.
Instead I would propose to allow this to be a function. Then if the reponse is not matching it could be updated by that. Like this:
@Response(type: User, transform: (input) => input.user)
public async get(id: string, parameters: any) : User {}
from pretend.
@caiobiodere I'll definitely build this this week I think.
from pretend.
thanks mate! I think that's good enough regarding it also fixes my case :)
from pretend.
Hi @caiobiodere,
I'm not sure if I understand what you are aiming at. What do you mean by 'return like a typescript class'?
Do you want to have the returned data wrapped in a class which is created based on the method which was called?
Would be nice to see some pseudocode you have in mind if you can write that down.
from pretend.
@KnisterPeter yeah that's exactly what I meant sorry english is not one of my best things yet, still getting in there :) yes sure can do that give me a couple of days will figure out how to do that
from pretend.
@KnisterPeter thanks for understanding mate!
getting into it, the idea behind all of this would be something similar to this:
type UserType {
id?: number
}
class User: UserType {
id?: number
constructor(id: number) {
this.id = id;
}
}
@Headers('Accept: application/json')
@Get('/user/{id}', true)
@Response(type: User | User[], keyPath: "userObject" | null) (the new decorator I mentioned before)
public async get(id: string, parameters: any) : User | User[] {}
from pretend.
Hi @caiobiodere,
this looks nice. Can you explain a bit what you need the keyPath
for? The type
is pretty obvious.
In general I could think of adding this feature, I like it.
from pretend.
Hi mate @KnisterPeter,
basically keyPath would be the path that it should extract the object to be wrapped from, lets say that we have a response like this:
{
user: {
id: 1
}
}
I could use keyPath as "user" and tell the decorator to wrap into the User class from it, this would save a lot of scenarios I can tell that because most of the time API's are not in the way you really want them to be
from pretend.
I like your idea better, do you want me to help with that? I really want this to be part of my current working project
from pretend.
You can give it a try. I would accept a PR if you like.
But I'm as well a bit biased and have an idea how I would implement this. Lets see, maybe I like your idea as well. 😃
from pretend.
Lets get this running, will be watching and forking this project from now on, do you have an idea of how much time would it take to you to get a first version of this done?
from pretend.
if you think you can finish this in a couple of days I can wait mate, that would be no problem at all
from pretend.
@KnisterPeter hey mate I saw you started it already, how is it going do you have an estimated time?
from pretend.
The PR could be reviewed by you, it's already done.
The tests should hold some examples.
Please give some feedback.
from pretend.
@caiobiodere Any comments or thoughts? I'd like to make a release out of this.
from pretend.
These are the docs in the README
from pretend.
Released in v3.1.0
from pretend.
Related Issues (11)
- Dist folder is not deployed with v4 HOT 1
- An in-range update of nock is breaking the build 🚨 HOT 2
- Action Required: Fix Renovate Configuration
- requestInterceptor: access request params before stringifyed HOT 2
- Why this lib so dead? HOT 1
- Can't call chain more than once in interceptor
- Can't declaration method return type HOT 2
- append dynamic headers HOT 3
- ReferenceError: Headers is not defined HOT 1
- Dependency Dashboard
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 pretend.