Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liveforeverx/apix
Simple convention and DSL for transformation of elixir functions to an API for later documentation and or validation.
https://github.com/liveforeverx/apix
Last synced: 3 months ago
JSON representation
Simple convention and DSL for transformation of elixir functions to an API for later documentation and or validation.
- Host: GitHub
- URL: https://github.com/liveforeverx/apix
- Owner: liveforeverx
- License: other
- Created: 2015-05-05T17:38:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-01T20:42:06.000Z (over 5 years ago)
- Last Synced: 2024-10-19T01:46:38.125Z (3 months ago)
- Language: Elixir
- Homepage:
- Size: 12.7 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Simple convention and DSL for transformation of elixir functions to an API for later documentation and or validation. (Macros)
- fucking-awesome-elixir - apix - Simple convention and DSL for transformation of elixir functions to an API for later documentation and or validation. (Macros)
- awesome-elixir - apix - Simple convention and DSL for transformation of elixir functions to an API for later documentation and or validation. (Macros)
README
Apix
====Simple convention and DSL for transformation of elixir functions to a documented and ready for validation API.
Example of usage (very simple get/put API):
```elixir
defmodule Simple.Api do
@moduledoc """
This api describes very simple get/put storage api.
And should be a very small example of how to use it.
"""
use Apix
@name "SimpleStore"
@tech_name "store"
api "Get", :get
api "Put", :putdef ensure_started() do
case Process.whereis(:simple) do
nil ->
{:ok, pid} = Agent.start_link(fn -> %{} end)
Process.register(pid, :simple)
_ ->
:ok
end
end@doc """
Get value for a defined key## Parameters
* `:key` - string, must be sent
* `:default` - string, optional, defines default, if nothing found to be returned## Results
"""
def get(%{key: key} = args) do
ensure_started()
%{result: Agent.get(:simple, &Map.get(&1, key, args[:default]))}
end@doc """
Put a value for the key## Parameters
* `:key` - string, describes key, on which it will be saved
* `:value` - string, describes value## Results
"""
def put(%{key: key, value: value} = _args) do
ensure_started()
Agent.update(:simple, &Map.put(&1, key, value))
%{result: true}
end
end
```Now, it is possible to get information to your API:
```elixir
iex> Apix.spec(Simple.Api, :methods)
["Get", "Put"]
iex> Apix.spec(Simple.Api, :method, "Put")
%{arguments: [key: %{description: "describes key, on which it will be saved", optional: false, type: "string"},
value: %{description: "describes value", optional: false, type: "string"}],
doc: "Put a value for the key"}
iex> Apix.spec(Simple.Api, :name)
"SimpleStore"
iex> Apix.spec(Simple.Api, :doc)
"This api describes very simple get/put storage api.\nAnd should be a very small example of how to use it.\n"
```There are some word in documetation, which will be identified, for example:
`## Parameters`, starting the attributes section.Each attribute should have the same format: "* `key` - type, description" or
"* `key` - type, optional, description". Type should be of type, which your validator
supports. Apix may support JSON validation in the future.For more information, use Apix documentation. All examples are actually tested with `doctest`.