GithubHelp home page GithubHelp logo

afaur / elixir-plug-api Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 49 KB

Starter for working with Elixir, Plug, and Cowboy. Provides an example of how to use a compiled eex template for a route. Has one API route with a test that validates it. Uses HTTPoison for testing a remote web request. Uses Poison for JSON encoding an API response. See `with_new_relic_agent` branch for an example of using new relic monitoring. Has code comments and getting started guide in readme.

License: The Unlicense

Elixir 95.01% Makefile 3.30% HTML 1.69%
elixir plug cowboy poison httpoison makefile justfile comments documentation unlicense

elixir-plug-api's Introduction

Build Status

Project Overview

  • Exposes one GET route
    • GET /api/users returns 200 OK result of ["Mary", "John", "Jill"]
  • Includes e2e test to check that the endpoint responds correctly
  • Uses four dependencies
    • Cowboy
      • Small Fast Http2 / Websocket Server
    • Plug
      • Middleware / Composable Modules
    • Poison
      • JSON Encoding / Decoding
    • HTTPoison
      • Testing Endpoints (Elixir CURL / Fetch)
      • Uses binaries instead of string lists
    • These deps do have sub deps
      • Goal is to minimize dep reliance as much as possible
  • See with_env_config branch which adds a make config task for creating .env from a .env_sample.
  • See with_new_relic_agent branch for an example of new relic monitoring.
  • See with_new_relic_agent_and_env_config branch for an example that combines the two individual branches together.

Organization

  • Uses a .lab folder, a Makefile, and a Justfile
    • .lab contains all mix new generated files / folders
    • Uses symlinks to / from .lab to simplify organization
    • Has a Makefile and Justfile to manage project commands

Laboratory Folder

  • Allows important folders / files to stay in the primary project dir
    • .lab folder is short for laboratory (where we mix our elixir :D)
      • src folder is linked to the lib folder in .lab
      • conf folder contains both the:
        • mix.exs from the root of .lab folder
        • config.exs from the config dir of .lab folder
      • test folder is linked to the test folder in .lab

Install Elixir

Using Make / Just

  • This project uses Make or Just to simplify mix and iex commands
  • If using just, replace all commands starting with make to just

Installing Make / Just

  • Having either one on your machine will work and setup is easy

Install Dependencies

  • make deps
    • See code in conf/mix.exs

Build Project

  • make build
    • See code in conf/*.exs

Running Project

  • Start the server
    • make run
  • See code in src/*.ex

Testing

  • How to test either manually or automatically

Manual Testing

  • After running make run you can either:
    • Use CURL
      • curl -v "http://127.0.0.1:8085/api/users"
    • Use Browser
      • open http://127.0.0.1:8085/api/users

Automatic Testing

  • ExUnit
    • make test
      • Runs project and asserts correct response is returned
      • See code in test/http_app_test.ex

elixir-plug-api's People

Contributors

afaur avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.