Move types for $Fetch from nitro to ofetch. #2157
Replies: 2 comments
-
Hi! I have been working on it for past couple of days. It is almost done. There are few thing to fix and discuss. While I was implementing it. I thought it is also time to change the structure of Here is now schema I come up with. interface ApiDefinition {
"/api/v1": {
default: {
response: { message: string };
};
};
"/api/v1/auth/register": {
post: {
response: { message: string };
request: {
body: {
name: string;
email: string;
username: string;
password: string;
};
};
};
};
"/api/v1/users/search": {
get: {
response: { users: { username: string }[] };
request: {
query: {
username: string;
};
};
};
};
"/api/users/:username": {
get: {
response: { user: { username: string; name: string; isFriend: boolean } };
request: {
params: {
username: string;
};
};
};
post: {
response: { message: string };
request: {
params: {
username: string;
};
};
};
};
} You can check out my version of implementation in There are some examples embedded in the I have also examples in I think it will be totally backward compatible but we will discuss. Also compatible with nitro because it fully override |
Beta Was this translation helpful? Give feedback.
-
Continued in the issue here. |
Beta Was this translation helpful? Give feedback.
-
@pi0 Hello! I am currently using
ofetch
for making request with other tools which doesn't use nitro. I needed features like retry and interceptors. It is working great and there is no issues.But, I would like to have some enhancements, like type-safety like nitro provide for API routes. I know I can make it work by copying types from https://github.com/unjs/nitro/blob/main/src/types/fetch.ts to my local dev env. But, It would be great if it will be officially supported in
ofetch
.In my opinion after the changes will be made API will look like this :-
The only problem I see is
RouterMethod
(here) which is being imported from h3, because h3 is not an dependency of ofetch. I think duplicating this type in ofech will not be a problem in long run.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions