Giter VIP home page Giter VIP logo

carraway's Introduction

Carraway

No longer maintained.

Build Status

A static-site helper which provides an API for contact form submissions and subscriptions.

Carraway

But why?

Static sites (e.g. Gatsby or Jekyll) are awesome - but there are limitations. Having a contact form or managing subscriptions is part of these limitations - without a proper API you can't just have these things.

There are solutions out there for contact form submissions and there are solutions out there for subscription management. I don't like to have many different services to maintain one single blog. It's just a blog.

Most of them either cost way too much for smaller projects (like a blog) or aren't working properly.

Additionally relying on third party services always mean giving data away.

Or maybe I'm just really bad at using Google and had too much time on my day off.

Features

  • Admin UI with multi user login
  • Contact form submission API
  • Subscription API
  • Mailchimp Integration which automatically syncs subscriptions

Requirements

  • PHP 7.1.3 or higher
  • SQLite

Installation

For webserver configuration of Symfony applications see the official Configuring a Web Server guide.

  1. Clone the repository git clone https://github.com/nehalist/carraway.git
  2. cd into the repo directory
  3. Install dependencies with composer install --no-dev --optimize-autoloader
  4. Create the database with bin/console doctrine:database:create
  5. Execute migrations with bin/console doctrine:migrations:migrate
  6. Create a user with bin/console app:create-user <name> <password>
  7. Copy and rename your .env file to .env.local and adjust its values (see below for dotenv file details)
  8. Clear your cache with APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear

Your admin is accessible at yourdomain.tld/admin

API

Carraway currently provides two different APIs: one for contact form submissions and one for subscriptions.

Contact Form Submission

Creates (and optionally saves, depending on SAVE_CONTACT_REQUESTS in your dotenv configuration) contact requests.

POST <carraway>/api/contact

Request
{
    name: string;
    mail: string;
    subject?: string;
    message: string;
}

Response
{
    name: string;
    mail: string;
    subject: string;
    message: string;
}

Subscriptions

POST <carraway>/api/subscription

Request
{
    name?: string;
    mail: string;
}

Response
{
    name: string;
    mail: string;
}

Errors

Errors do have proper status codes (4xx). API errors always are JSON formatted with an array of all errors, e.g.:

{
  "errors": [
    "Email already subscribed"
  ]
}

System errors (5xx) are also formatted the same way. Their content depend on the environment; while in dev proper exception messages are returned errors in prod only return

{
  "errors": ["System Error"]
}

The status code for reached API limits is 429.

fetch example

An example on how to interact with the API with fetch:

fetch(`<carraway>/api/contact`, {
  method: `post`,
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'John Doe',
    mail: '[email protected]',
    message: 'Howdy!'
  })
})
  .then(res => res.json())
  .then(res => console.log(res));

Dotenv file

App configuration is entirely done via .env (respectively .env.local) files.

value description
CONTACT_REQUEST_FROM Sender mail for contact form submissions
CONTACT_REQUEST_TO Receiver mail for contact form submissions
MAILCHIMP_API_KEY Your Mailchimp API Key
MAILCHIMP_API_URL Your Mailchimp API URL
MAILCHIMP_LIST_ID Your Mailchimp List ID where subscribers should be added / deleted
SAVE_CONTACT_REQUESTS If contact requests should be saved (hi @ GDPR)
DAILY_CONTACT_REQUESTS_LIMIT_PER_IP Maximum contact requests from one ip for one day

Important: NEVER change the .env file directly. Always create a copy from it (.env.local) and change this file!

Author & License

Created by nehalist.io - Released under the MIT license.

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.