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

Add support for "http" #157

Open
ccoVeille opened this issue Apr 2, 2024 · 10 comments
Open

Add support for "http" #157

ccoVeille opened this issue Apr 2, 2024 · 10 comments

Comments

@ccoVeille
Copy link
Contributor

ccoVeille commented Apr 2, 2024

Here is the documentation of an http request

```http
POST /login HTTP/1.1
Authorization: Bearer bar
Content-Type: application/json

{
"foo": true}
```

Here is a reply

````mardown
```http
HTTP 200 OK
Content-Type: application/json

{"success":      true  }

```

But it's not limited to json replies. It could return HTML/XML

It's a very used pattern in API documentation

The code snippets are badly indented on purpose.

@ccoVeille ccoVeille changed the title formatter http block support Here is a request formatter http block support Apr 2, 2024
@ccoVeille ccoVeille changed the title formatter http block support Add support for "http" Apr 2, 2024
@ccoVeille
Copy link
Contributor Author

http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html

Here is the RFC, knowing its number might help to find code/library to handle it

@hougesen
Copy link
Owner

Do you know any formatter that supports http files?

I have been thinking about adding a format command for hougesen/hitt, but has refrained from doing so since hitt supports some additional syntax (variables, comments, multiple requests in single file) that could result in breaking other tools.

@ccoVeille
Copy link
Contributor Author

I looked for many tools but I failed to

I know linguist, the library used by GitHub for code highlighting supports it. But there is no linter in it.

The biggest problem is that finding relevant content mentioning http, that's everywhere … it's uneasy

Also the http syntax is somehow only used in Markdown

I didn't look at AST based project or tree-sitter anyway. I'm dropping buzz words with no knowledge about tree-sitter

I found this lib by looking for "tree-sitter-http"

https://github.com/rest-nvim/tree-sitter-http

This one looks perfect if you understand how to use it, something I don't.

There might be something around mardown-it maybe. But I found nothing about markdown-it-http

I'm also thinking about VScode extension that allows to find send http headers from http block directly in the markdown preview. They have to parse the content to create the query.
It could be a good idea to look at this.

I found this one

https://github.com/Huachao/vscode-restclient
https://marketplace.visualstudio.com/items?itemName=mkloubert.vscode-http-client

@ccoVeille
Copy link
Contributor Author

I hope my detailed reply will help you.

I just opened the hitt project, and noticed it was yours haha.

My guess is that would be easy for you to build something.

But then, I'm wondering you may found a parser, but you are looking for a formatter.

So I'm insure what can be done. You might be able to write a parser, so you might be able to report obvious things like

  • no HTTP on the first line
  • missing empty line after headers
  • broken json
  • missing Content-Type application/json in the post or reply

this one is very common and leads to broken highlighting

Except formatting the JSON I'm unsure what you could format, and a few fixes. I'm unsure what you can format

Oh I also know sphinx-doc reports invalid blocks when parsing the doc block (because if highlight code), it could be useful to look at what they do

@ccoVeille
Copy link
Contributor Author

I hope you will read what I wrote @hougesen 😅🤣😂

Because my investigation took time

@hougesen
Copy link
Owner

Thank you for investigating! 😃

I read it yesterday, but still haven’t really made up my mind about what to do 😅

I wrote a custom parser for hitt since I wanted full control. So adding formatting abilities is definently an option.
Only issue would be that formatting the json body of a http request semantically alters the input. Which is the primary reason for me refraining from doing it.

Do you use the vs code extension?

@ccoVeille
Copy link
Contributor Author

I did, but I moved to Bruno, and recently ATAC

@ccoVeille
Copy link
Contributor Author

ccoVeille commented Jun 26, 2024

I would say create a lib in a separate repository.

Import it in mdsf, you will have support for http block.

You might add it to hitt, then maybe.

Everyone might have a need for a lib. Maybe @Julien-cpsn will have a need for https://github.com/Julien-cpsn/ATAC

Unless I'm wrong your two projects are I'm Rust

@ccoVeille
Copy link
Contributor Author

I opened #337

@ccoVeille
Copy link
Contributor Author

ccoVeille commented Jul 12, 2024

Just found

There is the httparse crate, it may help

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

2 participants