Server API

Introduction

Anis server provides a REST API to perform actions. In this section we will list the different endpoints.

You can find the list of all endpoints in the app/routes.php file. Each route refers to a class Action and when the endpoint is called it is the __invoke function that is executed.

Actions

You can find the Action files in the src/Action folder. You can modify one or more actions to change the behavior of an endpoint. You can also add an action file to add an entrypoint.

If you want to add an new action, you need to declare a new route into the app/routes.php file and you need to instantiate your new Action into the app/dependencies.php file.

Endpoints

Root

Used to ensure that the service is up.

URL : /

Method : GET

URL Params : None

Query Params : None

Auth required : No

Success Response :

Code : 200 OK

Content example

{
    "message": "it works!"
}

Retrieve database list

Used to retrieve business database list.

URL : /database

Method : GET

URL Params :

Query Params : None

Auth required : Yes

Success Response :

Code : 200 OK

Content example

[
    {
        "id": 1,
        "label": "Test",
        "dbname": "anis_test",
        "dbtype": "pdo_pgsql",
        "dbhost": "db",
        "dbport": 5432,
        "dblogin": "anis",
        "dbpassword": "anis"
    }
]

Add a new database

Used to add a new business database.

URL : /database

Method : POST

URL Params : None

Query Params : None

Body :

Name Description Type Available
label It is the label of the new entry string X
dbname Name of the new database string X
dbtype Doctrine driver of the database (pdo_pgsql, pdo_mysql, ...) string X
dbhost Database server hostname string X
dbport Database server listening port int X
dblogin User name for connection to the database string X
dbpassword Password for connection to the database string X

Auth required : Yes

Success Response :

Code : 201 Created

Content example

[
    {
        "id": 1,
        "label": "Test",
        "dbname": "anis_test",
        "dbtype": "pdo_pgsql",
        "dbhost": "db",
        "dbport": 5432,
        "dblogin": "anis",
        "dbpassword": "anis"
    }
]

Error Response :

Code : 400 Bad Request

Content example

{
    "message": "400 Bad Request",
    "exception": [
        {
            "type": "Slim\\Exception\\HttpBadRequestException",
            "code": 400,
            "message": "Param dbpassword needed to add a new database",
            "file": "/project/src/Action/DatabaseListAction.php",
            "line": 50
        }
    ]
}

Retrieve a database by ID

Used to retrieve one database by ID.

URL : /database/{id}

Method : GET

URL Params :

Name Description Type Available
id ID of the database int X

Query Params : None

Auth required : Yes

Success Response :

Code : 200 OK

Content example

{
    "id": 1,
    "label": "Test",
    "dbname": "anis_test",
    "dbtype": "pdo_pgsql",
    "dbhost": "db",
    "dbport": 5432,
    "dblogin": "anis",
    "dbpassword": "anis"
}

Error Response :

Code : 404 Not Found

Content example

{
    "message": "404 Not Found",
    "exception": [
        {
            "type": "Slim\\Exception\\HttpNotFoundException",
            "code": 404,
            "message": "Database with id 2 is not found",
            "file": "/project/src/Action/DatabaseAction.php",
            "line": 45
        }
    ]
}

Edit a database

Used to edit a business database.

URL : /database/{id}

Method : PUT

URL Params :

Name Description Type Available
id ID of the database int X

Query Params : None

Body :

Name Description Type Available
label It is the new label of the entry string X
dbname New name of the database string X
dbtype Doctrine driver of the database (pdo_pgsql, pdo_mysql, ...) string X
dbhost Database server hostname string X
dbport Database server listening port int X
dblogin User name for connection to the database string X
dbpassword Password for connection to the database string X

Auth required : Yes

Success Response :

Code : 200 Ok

Content example

{
    "id": 1,
    "label": "New label",
    "dbname": "anis_test",
    "dbtype": "pdo_pgsql",
    "dbhost": "db",
    "dbport": 5432,
    "dblogin": "anis",
    "dbpassword": "anis"
}

Error Response :

Code : 404 Not Found

Content example

{
    "message": "404 Not Found",
    "exception": [
        {
            "type": "Slim\\Exception\\HttpNotFoundException",
            "code": 404,
            "message": "Database with id 2 is not found",
            "file": "/project/src/Action/DatabaseAction.php",
            "line": 45
        }
    ]
}

Code : 400 Bad Request

Content example

{
    "message": "400 Bad Request",
    "exception": [
        {
            "type": "Slim\\Exception\\HttpBadRequestException",
            "code": 400,
            "message": "Param dbpassword needed to edit the database",
            "file": "/project/src/Action/DatabaseAction.php",
            "line": 61
        }
    ]
}

Delete a database by ID

Used to delete one database by ID.

URL : /database/{id}

Method : DELETE

URL Params :

Name Description Type Available
id ID of the database int X

Query Params : None

Auth required : Yes

Success Response :

Code : 200 OK

Content example

{
    "message": "Database with id 2 is removed!",
}

Error Response :

Code : 404 Not Found

Content example

{
    "message": "404 Not Found",
    "exception": [
        {
            "type": "Slim\\Exception\\HttpNotFoundException",
            "code": 404,
            "message": "Database with id 2 is not found",
            "file": "/project/src/Action/DatabaseAction.php",
            "line": 45
        }
    ]
}

Retrieve table list from a database

URL : /database/{id}/table

Method : GET

URL Params :

Name Description Type Available
id ID of the database int X

Query Params : None

Auth required : Yes

Success Response :

Code : 200 OK

Content example

[
    "obs_cat",
    "aspic_vipers_dr2_w1",
    "observations_info",
    "aspic_gama_g02",
    "hk",
    "observations",
    "rawproducts",
    "products",
    "sp_cards",
    "sp_cards_bak",
    "vhf",
    "ancillary_files",
    "calibpack",
    "obspack",
    "observation",
    "public.v_products",
    "public.v_rawproducts",
    "public.anis_observation",
    "public.v_obspack"
]

Error Response :

Code : 404 Not Found

Content example

{
    "message": "404 Not Found",
    "exception": [
        {
            "type": "Slim\\Exception\\HttpNotFoundException",
            "code": 404,
            "message": "Database with id 2 is not found",
            "file": "/project/src/Action/TableListAction.php",
            "line": 58
        }
    ]
}

Retrieve project list

Used to retrieve project list.

URL : /project

Method : GET

URL Params :

Query Params : None

Auth required : No

Success Response :

Code : 200 OK

Content example

[
    {
        "name": "anis_project",
        "label": "Anis Project Test",
        "description": "Project used for testing",
        "link": "http://project.com",
        "manager": "M. Durand",
        "id_database": 1
    },
    {
        "name": "svom",
        "label": "Svom Project Test",
        "description": "Project used for testing",
        "link": "http://svom.com",
        "manager": "S. Basa",
        "id_database": 1
    },
    {
        "name": "colibri",
        "label": "Colibri Project Test",
        "description": "Project used for testing",
        "link": "http://colibri.com",
        "manager": "S. Basa",
        "id_database": 1
    }
]

Add a new project

Used to add a new project.

URL : /project

Method : POST

URL Params : None

Query Params : None

Body :

Name Description Type Available
name Identifier name for the project string X
label Label of the new project entry string X
description Description of the project string X
link Link to the project website string X
manager Project manager string X
id_database ID of the database associated to the project string X

Auth required : Yes

Success Response :

Code : 201 Created

Content example

{
    "name": "new_project",
    "label": "New project label",
    "description": "Project used for testing",
    "link": "http://project.com",
    "manager": "S. Dupont",
    "id_database": 1
}

Error Response :

Code : 400 Bad Request

Content example

{
    "message": "400 Bad Request",
    "exception": [
        {
            "type": "Slim\\Exception\\HttpBadRequestException",
            "code": 400,
            "message": "Param id_database needed to add a new project",
            "file": "/project/src/Action/ProjectListAction.php",
            "line": 50
        }
    ]
}