kalachlegends

kalachlegends

Fast_postman_collection - Generative collection for Postman by Phoenix Router

This library helps you generate a Postman collection from your Phoenix router (MyApp.Router).
You can document your endpoints using @doc annotations for params, body, form data, and more.
Pipelines (plugs) can also be auto-scanned and added to the collection automatically.

Example generated collection:

collection

This library uses the official Postman schema: https://schema.postman.com/

Table of Contents

Installation

If available in Hex, the package can be installed
by adding fast_postman_collection to your list of dependencies in mix.exs:

def deps do
  [
    {:fast_postman_collection, "~> 0.1.8"}
  ]
end

Configure fast_postman_collection

  • router → your Phoenix router module (required)
  • pipe_tokens → put in your auth bearer (pipe_tokens: a list of pipeline plugs (like :admin_auth) that should automatically add a Bearer token in the Postman request headers.)
  • variables → variables to include in the Postman collection (optional)
  • file_path_collection → path to save the generated collection (optional)
config(:fast_postman_collection,
  pipe_tokens: [:admin_auth, :user_auth],
  name_collection: "My collection",
  router: MyApp.Router,
  variables: [
    %{
      key: "host",
      value: "http://localhost:4000"
    }
  ]
)

When you add router to your configuration, it will be able to generate a collection using the command - mix fs.get_collection

Description and Title of collection

naming

@moduledoc """
# Post Controller
This will be used as the folder name in the generated Postman collection.
"""

@doc """
# Create Post
This will be used as the request title in the Postman collection.

Use this endpoint to create a new post.
All content inside this doc block will be added to the request description in the collection.
"""

If you don’t provide a @doc annotation, the default name will be taken from the module or function name.

Params in Your Collection

These parameters will be included in the URL as query strings.
For example, the generated URL might look like: ?limit=0&page=1

@doc params: %{
  limit: 0,
  page: %{
    key: "page",
    value: 1,
    description: "Page number for pagination"
  }
}
def index(conn, params) do
  json(conn, params)
end

params

Body Parameters

These parameters will be included in the request body.
By default, the body is sent in JSON format.

This is how you define a request body in JSON format:

@doc """
# Create post
"""
@doc body: %{
        post: %{
          title: ""
        }
      }
def create_post(conn, params) do
  json(conn, params)
end

body

Formdata options

To send form data (e.g. file uploads):

@doc mode: "formdata"
@doc formdata: [
        %{
          key: "image",
          value: nil,
          type: "file"
        }
      ]

How to Auto-Scan and Apply Authentication Tokens

How to auto scan and autoput your pipe’s token

Example

router.ex

scope "/user" do
  pipe_through(:admin_auth)
  get("/", UserController, :index)
end

config.exs

config(:fast_postman_collection,
  pipe_tokens: [:admin_auth, :user_auth]

All tokens puts and scans from your pipelines

token

Extract Token from Response Automatically

You can also automatically insert tokens into variables from a response:

 @doc auth_pre_request: %{is_enabled: true, from_resp_token: "token", variable_token: "admin_variable"}

Organizing Folders in the Collection

You can use @moduledoc folder_path: “Admin” to place your module’s requests inside a specific folder in the Postman collection.

The final folder structure will look like:
Admin / UserController

Example

defmodule MyAppWeb.AdminUserController do
  use MyAppWeb, :controller
  @moduledoc folder_path: "Admin"
  # this module puts to /admin/user controller
  @moduledoc """
  # user controller
  """

end

Mix commands

  • mix fs.get_collection: This command generate in your directory file with collection

Todo

  • filtering in mix fs.get_collection

You like the idea?

If you like the idea of the library, write in this “issue” on github and I will add this functionality as soon as I have free time.

Documentation:

https://github.com/kalachlegends/fast_postman_collection

First Post!

arton

arton

This looks like a great library @kalachlegends ! I think having an easy way to generated API documentation from existing phoenix code is currently a missing feature of the ecosystem, so something like this could go a long way to improving it. Thanks for sharing!

Where Next?

Popular in Announcing Top

tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19228 141
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
384 13736 119
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement