GithubHelp home page GithubHelp logo

plumpmath / system-dependency-injection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danielsz/system-dependency-injection

0.0 0.0 0.0 19 KB

Example for dependency injection with system

Clojure 100.00%

system-dependency-injection's Introduction

Dependency injection example with system

Definition

This is a case study project for the system library, summing up practices that have emerged in the Clojure landscape.

It demonstrates the following:

Mission statement

Names are important. What names? Those behind our favorite movies, that’s who! So let’s save them via a web service.

Installation

In our development environment, we use a in-memory database and a web server listening on port 3025.

$ boot dev

Or, if you don’t intend to connect with a REPL to the running system, type simply:

$ boot dev-run

In our production environment, we use a persistent database and a web server listening on port 8008.

$ boot prod-run

Usage

To search for a movie’s director:

curl -H "Content-Type: application/edn" -X POST -d '{:movie "Realm of the Senses"}' http://localhost:3025/movie 
{:director ("Nagisa Ōshima")}

To add a director to our database:

curl -H "Content-Type: application/edn" -X PUT -d '{:director "Nagisa Ōshima"}' http://localhost:3025/director

To list directors in our database:

curl http://localhost:3025/directors
("Nagisa Ōshima")

Let’s look for another all-time favorite.

curl -H "Content-Type: application/edn" -X POST -d '{:movie "Professione: reporter"}' http://localhost:3025/movie 
{:director ("Michelangelo Antonioni")}

Now that we know the name of the director, we can persist it to our database.

curl -H "Content-Type: application/edn" -X PUT -d '{:director "Michelangelo Antonioni"}' http://localhost:3025/director

Let’s verify it’s there:

curl http://localhost:3025/directors
("Nagisa Ōshima" "Michelangelo Antonioni")

Let’s repeat this one more time for a third movie/director:

curl -H "Content-Type: application/edn" -X POST -d '{:movie " À bout de souffle"}' http://localhost:3025/movie 
{:director ("Jean-Luc Godard")}

Saving to database:

curl -H "Content-Type: application/edn" -X PUT -d '{:director "Jean-Luc Godard"}' http://localhost:3025/director

We should now have three directors in our database:

curl http://localhost:3025/directors
("Nagisa Ōshima" "Michelangelo Antonioni" "Jean-Luc Godard")

Let’s suppose we want to remove one.

curl -H "Content-Type: application/edn" -X DELETE -d '{:director "Nagisa Ōshima"}' http://localhost:3025/director

Let’s verify the removal was properly executed.

curl http://localhost:3025/directors
("Michelangelo Antonioni" "Jean-Luc Godard")

License

Distributed under the Eclipse Public License, the same as Clojure.

system-dependency-injection's People

Contributors

danielsz avatar kajism 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.