Giter Site home page Giter Site logo

mailbox-api's Introduction

Mailbox API

Description

A local firm is building a small E-mail client to manage their internal messaging. You have been asked to provide a simple prototype for a basic mailbox API in which the provided messages are listed. Each message can be marked as read and you can archive single messages.

Solution

Used technology

I choosed Laravel framework for this task, because of its simplicity and its powerful RESTful API handler.

Installation

To install the app, first clone the repo

git clone https://github.com/othmanus/mailbox-api.git

And then update with composer

composer update

Import messages from a JSON file

First, you need to create the table and change the configurations in .env file at the root of the project.

Then, go to the command line and type the following command:

php artisan migrate --seed

The command will create the messages table and import the json file to seed it.

The messages contains the following attributes:

- id: integer // primary key
- sender: string
- subject: string
- message: string
- time_sent: datetime
- is_read: boolean // false by default
- time_read: datetime // read timestamp
- is_archived: boolean // false by default
- time_archived: datetime // archived timestamp

The creation of the table is defined in ./database/migrations/##_create_messages_table.php

To import the json file, I first pasted a copy of it in ./storage/app/messages_sample.json And then, I created a Seeder (./database/seeds/MessagesTableSeeder.php), in which we read the json file and import the content into the database.

To run the app, use the following command:

php artisan serve

It should be running on http://localhost:8000

### Message API Using the ./app/Message.php model, which contains all the previous attributes, we can interact easly with the database.

All the routes are listed in ./routes/api.php which is protected by a middleware by default. The routes are:

- /api/messages : list of all messages
- /api/messages/archived : list of all archived messages
- /api/messages/{id} : show a message
- /api/messages/{id}/read : read a message
- /api/messages/{id}/archive : archive a message

All the actions are routed to the controller ./app/Http/Controllers/Api/MessagesController.php.

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.