cevado

cevado

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

repo: GitHub - fcevado/ecto_api · GitHub
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 Switch mode

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?

Trending in Announcing Top

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...
385 14863 120
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
zachdaniel
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses: I had hope...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
yureehuh
Introduction Founded in 2017 by landscape ecologist and fire mitigation expert Harry Statter, Frontline developed the first fully integra...
New

We're in Beta

About us Mission Statement