wet-sandwich / hyper.nvim

MIT License
42 stars 0 forks source link

Add Support for Reading Requests from a `.http` File #14

Open nitaicharan opened 1 week ago

nitaicharan commented 1 week ago

Description: The hyper.nvim plugin is an excellent tool for Neovim users, offering a variety of functionalities to enhance productivity. To further extend its capabilities, it would be beneficial to add support for reading HTTP requests directly from a .http file. This feature would allow users to manage and execute HTTP requests seamlessly within Neovim, improving their workflow, especially for developers working with APIs.

Proposed Features:

  1. Parsing .http Files:

    • Implement a parser to read and interpret .http files.
    • Ensure the parser can handle various HTTP methods (GET, POST, PUT, DELETE, etc.).
    • Support for defining request headers, body, and query parameters within the .http file.
  2. Executing Requests:

    • Integrate with an HTTP client library to execute the parsed requests.
    • Allow users to execute individual requests or all requests within the file.
    • Display response status, headers, and body within Neovim.
  3. Environment Variables:

    • Allow users to add placeholders in the .http file to include environment variables.
    • Implement a mechanism to replace placeholders with actual environment variable values at runtime.
    • Support for defining environment variables within Neovim or sourcing them from an external file.
  4. Documentation:

    • Update the hyper.nvim documentation to include usage instructions for the new .http file support.
    • Provide examples and best practices for creating and using .http files with environment variable placeholders.

Benefits:

References:


Example:


### Example .http file

# Simple GET request
GET https://api.example.com/users

# POST request with JSON body
POST https://api.example.com/users
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john.doe@example.com"
}

# PUT request with URL parameters
PUT https://api.example.com/users/123
Authorization: Bearer {{BEARER_TOKEN}}

{
  "email": "john.newemail@example.com"
}
nitaicharan commented 1 week ago

Thanks for the plugin. I created this issue because it's a missing functionality that would be amazing to have.

nitaicharan commented 1 week ago

Another functionality that would make me stop using other REST clients is the ability to make requests in a chain. I would execute one request and then use the information (e.g., token, ID, etc.) from that request in subsequent requests without having to manually make each one individually. However, first, I need to save the request configuration and response before making another request. This is why I created this issue.

wet-sandwich commented 6 days ago

Hi @nitaicharan, thank you for your input! I have already started work on adding support for API collections using .http files. I have taken some time off from working on hyper.nvim but I am looking to pick it back up.

Regarding proposed feature 3, the plugin already supports .env files, and since .http files are likely to be tracked in version control they are not a great place to store potentially sensitive information.

I like the idea of chaining requests and using the response of previous requests as input to subsequent ones. I will add this to the roadmap!