/ src / content / posts / rest-client-for-vim.mdx
rest-client-for-vim.mdx
 1  ---
 2  title: Simple TUI-based Rest Client for (Neo)vim
 3  date: 2020-07-16
 4  description: A post where I try to find a TUI alternative to Postman. In other word, REST client but in TUI
 5  tags:
 6      - neovim
 7  ---
 8  
 9  # Introduction
10  
11  I've been learning backend web development stuff lately to create an API and whatnot. We all know that a popular REST client to test API is [Postman](https://postman.com). I like it but it is using Electron which means that it is quite heavy. Well, to be honest it is not that heavy but if I can save more RAM then why won't I find an alternative for it.
12  
13  I found a really cool extension on vscode where you just need a file with the specified syntax to make a request. You might know that I use Neovim as my main editor, so I'm pretty sure there's a few that works like this. Guess what, there is.
14  
15  # Rest Clients
16  
17  ## Vim HTTP
18  
19  I came across this nice plugin called [vim-http](https://github.com/nicwest/vim-http). I like how it works, it has syntax highlighting for .http file which is basically a temporary file that you use to make a request. But the drawback to me is that it doesn't format json response. So I have to format it through the API which I don't like. So in the end, I try to find another restclient.
20  
21  ## Vim Rest Console
22  
23  I found this plugin called [vim-rest-console](https://github.com/diepm/vim-rest-console), but when I look at its syntax, I don't quite like it. So I never tried it in the end.
24  
25  ## COC Rest Client
26  
27  I'm using a plugin called coc.nvim, and it usually has a lot of stuff. So I checked if there's any for coc, turns out, there is. It's called [coc-restclient](https://github.com/pr4th4m/coc-restclient).
28  
29  Since most of coc plugins comes from vscode, this particular plugin works similar like the [one that vscode has](https://marketplace.visualstudio.com/items?itemName=humao.rest-client). Here's an example.
30  
31  ```
32  POST http://localhost:3000/api/user/register HTTP/1.1
33  Content-Type: application/json
34  
35  {
36    "username": "coolguy32",
37    "email": "im@coolguy.me",
38    "password": "superstronkpassword"
39  }
40  ```
41  
42  The great thing about this plugin is that, it gives the response in a json formatted file which is what I was looking for. Here's an example of the response after running `:CocCommand rest-client.request`.
43  
44  ```
45  {
46    "Status": 200,
47    "Message": "OK"
48  }
49  
50  {
51    "X-Powered-By": "Express",
52    "Content-Type": "application/json; charset=utf-8",
53    "Content-Length": "56",
54    "ETag": "W/\"38-Eu4y++fOI89s+z200P0DrHLf1ZE\"",
55    "Date": "Thu, 16 Jul 2020 14:35:10 GMT",
56    "Connection": "close"
57  }
58  
59  {
60    "msg": "User 5f10659e630bfa40702160e9 has been created"
61  }
62  ```
63  
64  Please refer to the repository for installation or configuration because they explain it really well, there's no point of me explaining it here :D
65  
66  import Update from "~/components/Update.astro";
67  
68  <Update date="2021-04-19">
69  
70  In the midst of lua hype, I found [this plugin](https://github.com/NTBBloodbath/rest.nvim) which doesn't depend on coc.nvim
71  It has a similar JSON output which is nice
72  
73  </Update>
74  
75  # Conclusion
76  
77  I'm glad I found this plugin because I am no longer need postman. I might need it for more advanced feature, but for now, simple rest client is fine. I don't have to leave my terminal and go to a separate program for that which is awesome. My current setup is having 3 tmux panes, 1 for Neovim, 1 for running the server and stuff, 1 for the rest client.