khoj-ai / khoj

Your AI second brain. Get answers to your questions, whether they be online or in your own notes. Use online AI models (e.g gpt4) or private, local LLMs (e.g llama3). Self-host locally or use our cloud instance. Access from Obsidian, Emacs, Desktop app, Web or Whatsapp.

Home Page:https://khoj.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can change GET to POST?[IDEA]

melfebulu opened this issue · comments

commented

Describe the feature you'd like

A clear and concise description of what you want to happen. Include any relevant links or screenshots or inspiration.

hello, I check the source code in /src/khoj/interface/web/chat.html

here is use GET but not POST

let url =/api/chat?q=${encodeURIComponent(query)}&n=${resultsCount}&client=web&stream=true&conversation_id=${conversationID}&region=${region}&city=${city}&country=${countryName};

I asked gpt,so the answer is :

This line of code constructs a URL that includes the query parameters and other information collected from the front end. Then, this URL is used in a fetch() call, which effectively sends a GET request to the server. This process involves:

Retrieving the user input for the query.
Encoding the query content along with other relevant information (such as result count, client type, session ID, and geographical location information, etc.) into the URL's query string.
Using this URL to initiate a network request to the server-side corresponding API endpoint through the browser.
In this process, after receiving this GET request, the server processes it based on the request's parameters and returns the appropriate data.

If you want to change to using the POST method to submit information, you need to modify this part of the logic, create a request body, and then send this request body via a POST request, instead of appending all information in the query string of the URL. One advantage of doing this is that POST requests do not expose data in the URL, making them suitable for sending large amounts of data or sensitive information.

Hey @melfebulu ! Was there a particular reason why you wanted to use POST over GET here? I certainly see your point, wouldn't mind switching over, but curious to hear if you hit a specific limitation.

commented

long query string may cause Web browser reject.