|
@@ -6,11 +6,102 @@ Ruby 3.0.1 // Rails 6.1.3.1
|
6
|
6
|
Voir [cet article](https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-18-04) pour installer Ruby avec Rbenv, un gestionnaire de version pour Ruby.
|
7
|
7
|
Installer rails : `gem install rails -v 6.1.3.1`
|
8
|
8
|
|
|
9
|
+### 0. Pré-requis
|
|
10
|
+
|
|
11
|
+PostgreSQL 11 minimum et la gem associée (`pg`).
|
|
12
|
+
|
9
|
13
|
### 1. Installation
|
10
|
14
|
1. `bundle install`
|
11
|
15
|
2. `rails db:migrate` (et `rails db:seed` pour peupler la db avec des données factices, si nécessaire)
|
12
|
|
-3. `rails server` pour lancer un serveur local sur le port 3000
|
|
16
|
+3. `rails server` pour lancer un serveur local de développement sur le port 3000
|
13
|
17
|
|
14
|
18
|
### 2. Endpoints
|
15
|
19
|
La commande `rails routes` fournie l'ensemble des endpoints et requêtes HTTP disponibles. L'ensemble des requêtes se font sur la base : localhost:3000/api/v1.
|
16
|
20
|
|
|
21
|
+## Appel de l'API
|
|
22
|
+
|
|
23
|
+### Créer un compte utilisatrice
|
|
24
|
+
|
|
25
|
+`POST /api/v1/users(.:format) api/v1/users#create {:format=>:json}`
|
|
26
|
+
|
|
27
|
+```bash
|
|
28
|
+curl --header "Content-Type: application/json" -d "{\"user\" : { \"username\" : \"test\", \"password\" : \"lepwd\", \"email\" : \"iel@cli.su\" }}" -XPOST https://chronobriq-api.URL/api/v1/users
|
|
29
|
+```
|
|
30
|
+
|
|
31
|
+### Obtenir un token
|
|
32
|
+
|
|
33
|
+`POST /api/v1/tokens(.:format) api/v1/tokens#create {:format=>:json}`
|
|
34
|
+
|
|
35
|
+```bash
|
|
36
|
+curl --header "Content-Type: application/json" -d "{\"user\":{\"email\":\"iel@cli.su\", \"password\":\"lepwd\"}}" -XPOST https://chronobriq-api.URL/api/v1/tokens
|
|
37
|
+```
|
|
38
|
+
|
|
39
|
+Un obtient une réponse du type :
|
|
40
|
+
|
|
41
|
+```
|
|
42
|
+{"token":"Kgt2p1ITAjfbLK4xtS8YPi44gIMWrwtagOGwK0ROEOUgrn6Jj34sqprnX2d7t7RI","email":"jules@cli.coop","username":"test"}
|
|
43
|
+```
|
|
44
|
+
|
|
45
|
+#### Usage
|
|
46
|
+
|
|
47
|
+Grâce au to.ken obtenu précédemment, nous pouvons récupérer des informations en le fournissant dans l'entête
|
|
48
|
+
|
|
49
|
+##### GET
|
|
50
|
+
|
|
51
|
+- Users
|
|
52
|
+
|
|
53
|
+```
|
|
54
|
+curl --header "Content-Type: application/json" -H "Authorization : Kgt2p1ITAjfbLK4xtS8YPi44gIMWrwtagOGwK0ROEOUgrn6Jj34sqprnX2d7t7RI" -XGET https://chronobriq-api.canaille.netlib.re/api/v1/users
|
|
55
|
+```
|
|
56
|
+
|
|
57
|
+- Teams
|
|
58
|
+
|
|
59
|
+```
|
|
60
|
+curl --header "Content-Type: application/json" -H "Authorization: Kgt2p1ITAjfbLK4xtS8YPi44gIMWrwtagOGwK0ROEOUgrn6Jj34sqprnX2d7t7RI" -XGET https://chronobriq-api.canaille.netlib.re/api/v1/teams
|
|
61
|
+```
|
|
62
|
+
|
|
63
|
+## Notes
|
|
64
|
+
|
|
65
|
+Patch et delete permettent de modifier ou supprimer une donnée qui a été crée depuis cette utilisatrice, après avoir spécifié l'id du jeu de données dans l'URL
|
|
66
|
+
|
|
67
|
+### Routes
|
|
68
|
+
|
|
69
|
+| Prefix | Verb | URI Pattern | Controller#Action |
|
|
70
|
+| -------------------- | ------ | ---------------------------------------------------------- | ------------------------------------------- |
|
|
71
|
+| api_v1_users| GET | /api/v1/users(.:format) | api/v1/users#index {:format=>:json} |
|
|
72
|
+| | POST | /api/v1/users(.:format) | api/v1/users#create {:format=>:json} |
|
|
73
|
+| api_v1_user| GET | /api/v1/users/:id(.:format) | api/v1/users#show {:format=>:json} |
|
|
74
|
+| | PATCH | /api/v1/users/:id(.:format) | api/v1/users#update {:format=>:json} |
|
|
75
|
+| | PUT | /api/v1/users/:id(.:format) | api/v1/users#update {:format=>:json} |
|
|
76
|
+| | DELETE | /api/v1/users/:id(.:format) | api/v1/users#destroy {:format=>:json} |
|
|
77
|
+| api_v1_tokens| POST | /api/v1/tokens(.:format) | api/v1/tokens#create {:format=>:json} |
|
|
78
|
+| api_v1_teams| GET | /api/v1/teams(.:format) | api/v1/teams#index {:format=>:json} |
|
|
79
|
+| | POST | /api/v1/teams(.:format) | api/v1/teams#create {:format=>:json} |
|
|
80
|
+| api_v1_team| GET | /api/v1/teams/:id(.:format) | api/v1/teams#show {:format=>:json} |
|
|
81
|
+| | PATCH | /api/v1/teams/:id(.:format) | api/v1/teams#update {:format=>:json} |
|
|
82
|
+| | PUT | /api/v1/teams/:id(.:format) | api/v1/teams#update {:format=>:json} |
|
|
83
|
+| | DELETE | /api/v1/teams/:id(.:format) | api/v1/teams#destroy {:format=>:json} |
|
|
84
|
+| api_v1_memberships| GET | /api/v1/memberships(.:format) | api/v1/memberships#index {:format=>:json} |
|
|
85
|
+| | POST | /api/v1/memberships(.:format) | api/v1/memberships#create {:format=>:json} |
|
|
86
|
+| api_v1_membership| GET | /api/v1/memberships/:id(.:format) | api/v1/memberships#show {:format=>:json} |
|
|
87
|
+| | PATCH | /api/v1/memberships/:id(.:format) | api/v1/memberships#update {:format=>:json} |
|
|
88
|
+| | PUT | /api/v1/memberships/:id(.:format) | api/v1/memberships#update {:format=>:json} |
|
|
89
|
+| | DELETE | /api/v1/memberships/:id(.:format) | api/v1/memberships#destroy {:format=>:json} |
|
|
90
|
+| api_v1_activity_tasks| GET | /api/v1/activities/:activity_id/tasks(.:format) | api/v1/tasks#index {:format=>:json} |
|
|
91
|
+| | POST | /api/v1/activities/:activity_id/tasks(.:format) | api/v1/tasks#create {:format=>:json} |
|
|
92
|
+| api_v1_activity_task| GET | /api/v1/activities/:activity_id/tasks/:id(.:format) | api/v1/tasks#show {:format=>:json} |
|
|
93
|
+| | PATCH | /api/v1/activities/:activity_id/tasks/:id(.:format) | api/v1/tasks#update {:format=>:json} |
|
|
94
|
+| | PUT | /api/v1/activities/:activity_id/tasks/:id(.:format) | api/v1/tasks#update {:format=>:json} |
|
|
95
|
+| | DELETE | /api/v1/activities/:activity_id/tasks/:id(.:format) | api/v1/tasks#destroy {:format=>:json} |
|
|
96
|
+| api_v1_activities| GET | /api/v1/activities(.:format) | api/v1/activities#index {:format=>:json} |
|
|
97
|
+| | POST | /api/v1/activities(.:format) | api/v1/activities#create {:format=>:json} |
|
|
98
|
+| api_v1_activity| GET | /api/v1/activities/:id(.:format) | api/v1/activities#show {:format=>:json} |
|
|
99
|
+| | PATCH | /api/v1/activities/:id(.:format) | api/v1/activities#update {:format=>:json} |
|
|
100
|
+| | PUT | /api/v1/activities/:id(.:format) | api/v1/activities#update {:format=>:json} |
|
|
101
|
+| | DELETE | /api/v1/activities/:id(.:format) | api/v1/activities#destroy {:format=>:json} |
|
|
102
|
+| api_v1_tasks| GET | /api/v1/tasks(.:format) | api/v1/tasks#index {:format=>:json} |
|
|
103
|
+| | POST | /api/v1/tasks(.:format) | api/v1/tasks#create {:format=>:json} |
|
|
104
|
+| api_v1_task| GET | /api/v1/tasks/:id(.:format) | api/v1/tasks#show {:format=>:json} |
|
|
105
|
+| | PATCH | /api/v1/tasks/:id(.:format) | api/v1/tasks#update {:format=>:json} |
|
|
106
|
+| | PUT | /api/v1/tasks/:id(.:format) | api/v1/tasks#update {:format=>:json} |
|
|
107
|
+| | DELETE | /api/v1/tasks/:id(.:format) | api/v1/tasks#destroy {:format=>:json} |
|