-
Notifications
You must be signed in to change notification settings - Fork 0
How It Works
What ?
This section describes how AIOMedia has been built and which technologies/standards has been used. You will also learn why the application has been designed this way, and if needed, the pros and cons this architecture.
Who ?
For developers who wants to :
- learn more about how it works internally.
- develop features for their instance of AIOMedia
- integrate AIOMedia to their existing Media/Home Improvement system
- replace some parts of the application by their own implementation (e.g. replace the server or the user interface)
- contribute to the core of AIOMedia
Basically, this application is an aggregate of two applications : the Server and the Client.
|- bin/
| `- www
|- client/
| |- public/
| | |- css/
| | |- fonts/
| | |- images/
| | |- js/
| | |- less/
| | `- favicon.ico
| |- src/
| `- index.html
`- server/
It is a RESTful API provided by Node.js.
Files and directories of the Server are :
-
bin/contains the application commands-
wwwstart command of the Server
-
-
server/contains the Server application
It is an HTML/AngularJS user interface completely independent from the Server. It will call the Server API with AJAX to retrieve JSON data. As it's just HTML & JavaScript, it doesn't require any server side process to run.
Files and directories of the Client are :
-
client/contains the Client application-
public/contains all public assets (css, images, js, less, favicon, etc.) -
src/contains AngularJs source files -
index.htmlentry point of the Client
-
Why ?
The API implements a Response object which is returned to the client in JSON format.
A response MUST contain at least :
- a status code : a specific status code for the application mapped to an HTTP status code (see list below)
- a message : a human-readable message that give additional information about what has been occurred on server
It can also contains additional fields (depending on Response type), like data (e.g. a collection, a specific item) or metadata (e.g. pagination, number of results). See Response types for more information about what is contained in each Response type.
Application status are mapped on the HTTP status codes, and have some others for those who lack (which are also mapped to existing HTTP codes). This is the exhaustive list of built in status and their respective HTTP status and their default message.
| Status Key | Status Code | HTTP Status Code | Message | Description |
|---|---|---|---|---|
| OK | 200 | 200 | OK | |
| NO_RESULT | 200 | 200 | No result | |
| UPDATED | 200 | 200 | Updated | |
| CREATED | 201 | 201 | Created | |
| ACCEPTED | 202 | 202 | Accepted | |
| BAD_REQUEST | 400 | 400 | Bad Request | |
| INVALID | 400 | 400 | Invalid Data | |
| NOT_FOUND | 404 | 404 | Not found | |
| UNAUTHORIZED | 401 | 401 | Unauthorized | |
| FORBIDDEN | 403 | 403 | Forbidden | |
| SERVER_ERROR | 500 | 500 | Internal Server Error | |
| UNAVAILABLE | 503 | 503 | Service Unavailable |
AIOMedia comes with a pre-built set of Response types.
Response types are shorthands to create the correct Response Object (with the correct status and message) for the most common responses you need. This permits a normalization of the API Responses and avoid you to rack your brains to know which status use for your response.
All Response constructors accept a custom message, if you want to provide more detailed information about what occurred on server (e.g. User Created instead of Created).
Below you'll find the list of Response types and when to use it.
new Response.Default([message]);new Response.Accepted([message]);new Response.Data.Item(data, [message]);new Response.Data.Collection(data, [message]);new Response.Data.Created(data, [message]);new Response.Data.Updated(data, [message]);new Response.Data.NoResult([message]);new Response.Data.NotFound([message]);new Response.Data.Invalid(data, errors, [message]);new Response.Error.NotFound([message]);new Response.Error.Unauthorized([message]);new Response.Error.Forbidden([message]);new Response.Error.Internal([message]);new Response.Error.Unavailable([message]);