cevado

cevado

EctoApi - a library to use Ecto to describe external api resources

repo: GitHub - fcevado/ecto_api
This is one idea that I’ve been experiment with and I’m making it public so there can be some discussion to improve these ideas.
Although the name initially might drive someone to think that it’s only for http api, the way i’m envisioning this is that it can be used with any sort of communication protocol.
Even asynchronous protocols might fit here.

Proposed API

I’m thinking t mimic Ecto.Repo for EctoApi with some restrictions and additions:

  • insert_all and update_all aren’t planned to be available.
  • all might happen, but not soon. I’m still uncertain if it’s better to support a limitted version of Ecto.Query or build a proper DSL for this.
  • get_by from Ecto.Repousually just return a single entry so for the current lack of all I’m adding get_all.
  • I’m currently working on how preload should work.
  • so the available functions are insert, update, delete, get, get_by, get_all.

Example:


defmodule User do
  use Ecto.Schema

  @schema_prefix "http://reqres.in/api"
  schema "/users" do
    field(:email, :string)
    field(:first_name, :string)
    field(:last_name, :string)
    field(:avatar, :string)
  end
end

usage:

#insert
%User{}
|> User.changeset(%{first_name: "John", last_name: "Doe"})
|> EctoApi.insert(resolver: EctoApi.Resolvers.Rest, client: EctoApi.Clients.Http, builder: User)

#update
{:ok, user} =
  %User{}
  |> User.changeset(%{first_name: "John", last_name: "Doe"})
  |> EctoApi.insert(resolver: EctoApi.Resolvers.Rest, client: EctoApi.Clients.Http, builder: User)

user
|> User.changeset(%{first_name: "Janet", last_name: "Doe"})
|> EctoApi.update(resolver: EctoApi.Resolvers.Rest, client: EctoApi.Clients.Http, builder: User)

#delete
{:ok, user} =
  %User{}
  |> User.changeset(%{first_name: "John", last_name: "Doe"})
  |> EctoApi.insert(resolver: EctoApi.Resolvers.Rest, client: EctoApi.Clients.Http, builder: User)

user
|> EctoApi.delete(resolver: EctoApi.Resolvers.Rest, client: EctoApi.Clients.Http, builder: User)

#get
User
|> EctoApi.get(6, resolver: EctoApi.Resolvers.Rest, client: EctoApi.Clients.Http, builder: User)

i’d like to get some opinions on what have been done so far and some solutions for the issues that I’m having so far(they’re described in the repo readme). I’d like to keep the discussions over the issues of the repo, but I’ll be checking this thread for sure.

Most Liked

thojanssens1

thojanssens1

I suggest that you mention the intent of the library more clearly and faster.

When looking at the readme, there’s a lot of text (you first state you have an idea you want to make public, then talk about the API, the issues you had, etc.) while it’s still not clear what the library offers.

I think you should first mention what this library does for you and what it saves you (as I think the goal is to write less code?).

Where Next?

Popular in Libraries Top

kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
josevalim
EDIT: since Ecto 3.0 final version is out, this post was amended to use the final versions in the instructions below. Hi everyone, We a...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
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
ericlathrop
I built a silly site for Halloween that uses Phoenix Channels on the backend, and React on the frontend. I had many problems integrating ...
New
KallDrexx
For a good number of months I've been working on creating a very basic RTMP live video streaming server. Now that I have a very, very ba...
New

Other popular topics Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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

Sub Categories:

We're in Beta

About us Mission Statement