Giter Site home page Giter Site logo

haskell-rest-dsl's Introduction

crud-generator-haskell

crud-generator-haskell is a tool for generating CRUD (Create, Read, Update, Delete) APIs for a given data model. It is designed to simplify the process of creating a RESTful API by automating the repetitive tasks involved in generating a CRUD API.

Defining Models

To use crud-generator, you must define data model using a JSON template, like this:

{
  "name": "user",
  "prefix": "api",
  "entity": "User",
  "fields": [
    {
      "fieldName": "name",
      "fieldType": "text"
    },
    {
      "fieldName": "surname",
      "fieldType": "text"
    }
  ]
}

you can define as many models as you project need.

How to run

To use crud-generator with stack, follow these steps:

  1. First, ensure that you have Stack installed on your system.

  2. If you dont have sqlite3 installed, you can download and install.

  3. Open a terminal and navigate to the root directory of your project.

  4. Start the stack ghci REPL by running the following command:

  stack ghci

In the REPL, run the migrateModel function, passing in the connection string for your database, default is db.sqlite3:

  migrateModel connectionString

This will create the necessary tables in database to support the generated API.

  1. Exit the REPL by typing :quit.

  2. Finally, start the server by running the following command:

After running these commands, exit from stack ghci and run the following command to start the server on port 8080:

  stack run

Or if you prefer, open two terminals side by side, in the first terminal. Run the following command to continuously monitor the source files and trigger a rebuild whenever any file changes:

  stack build --file-watch

So, after this, the project rebuilt whenever a file is modified.

In the second terminal. Run the following command to start the server on port 8080. Where api is defined in package.yaml

  stack exec api

Testing the Generated API

To test if was working was expect, try to make a request to model that you define, example:

  curl --location --request GET 'localhost:8080/api/user'

And this should return a list of user.

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.