Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about append default header for axios and typescript style. #40

Open
ynishi opened this issue Nov 24, 2019 · 0 comments
Open

How about append default header for axios and typescript style. #40

ynishi opened this issue Nov 24, 2019 · 0 comments

Comments

@ynishi
Copy link

ynishi commented Nov 24, 2019

Hi there, very thanks to make js interface from type based safety api!

I used 'type to axios style api', and thought that it is more useful for development(flexibility) to inject default header "Content-value 'application/json'" and body as {}(this maybe axios behavior likely bug. When none body is passed, header is not inject if header value is passed.).

How about inject axios default header Content-Type 'application/json' and body as {} or merged with body like {...body}?
Example output like below.

export interface XRequest {
  xId: XID;
  message: string;
}

// this setting supports cors(of course when server support)
export const postX = (body: XRequest) => {
  return axios.post(
    endpoint + "/conv",
    { ...body },
    {
      headers: {
        "Content-Type": "application/json"
      }
    }
  );
};

I think it is easy to fix and provide more seamless work for api with client lib also under development environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant