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

Infer HTTP method if not specified #5

Merged
merged 6 commits into from
Jan 5, 2021
Merged

Conversation

ducaale
Copy link
Owner

@ducaale ducaale commented Jan 5, 2021

This PR adds support for omitting the HTTP method in which case it will default to GET if the body is empty or to POST otherwise.

http :8080/users               # will be translated to `http get :8080/users`
http :8080/users name=ali      # will be translated to `http post :8080/users name=ali`
http put :8080/users name=ali  # it is still possible to specify the HTTP method

This is a hacky and temporary solution to issue #2. Here are the drawbacks I can think of so far:

  1. The Method and the URL are now treated as one in the manpages

Before

USAGE:
    ht [FLAGS] [OPTIONS] <METHOD> <URL> [REQUEST_ITEM]...
ARGS:
    <METHOD>             The HTTP method to be used for the request [possible values: GET, POST, PUT, PATCH, DELETE]
    <URL>
    <REQUEST_ITEM>...    Optional key-value pairs to be included in the request

After

USAGE:
    ht.exe [FLAGS] [OPTIONS] <[METHOD] URL> [REQUEST_ITEM]...

ARGS:
    <[METHOD] URL>
    <REQUEST_ITEM>...    Optional key-value pairs to be included in the request
  1. It is not possible to have a flag between the Method and the URL. For example, the following will not be a valid usage anymore
ht post --offline httpbin.org/post name=ahmed

Instead, any flags should be before the Method or after the URL

ht --offline post httpbin.org/json name=ahmed
ht post httpbin.org/json --offline name=ahmed

Closes #2

@ducaale ducaale merged commit b9a53f5 into master Jan 5, 2021
@ducaale ducaale deleted the feature/optional-method branch January 5, 2021 18:00
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

Successfully merging this pull request may close these issues.

Allow omission of the HTTP method
1 participant