Skip to content

Commit b79423e

Browse files
authored
Correction Lorène (checker //)
1 parent 9b8b603 commit b79423e

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

rails6/en/chapter02-api.adoc

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[#chapter02-api]
22
= The API
33

4-
In this section I’ll outline the application. By now you should have the bare bones of the application. If you did not read it I recommend you to do it.
4+
In this section I’ll outline the application. By now you should have read the previous chapter. If you did not read it I recommend you to do it.
55

66
You can clone the project until this point with:
77

@@ -19,7 +19,7 @@ As we want to go simple with the application it consists on five models. Don’t
1919

2020
image:data_model.png[Schema of links betweens models]
2121

22-
In short terms we have the `user` who will be able to place many `orders`, upload multiple `products` which can have many `images` or `comments` from another users on the app.
22+
In short terms the `user` will be able to place many `orders`, upload multiple `products` which can have many `images` or `comments` from another users on the app.
2323

2424
We are not going to build views for displaying or interacting with the API, so not to make this a huge tutorial, I’ll let that to you. There are plenty of options out there like javascript frameworks (https://angularjs.org/[Angular], https://vuejs.org/[Vue.js], https://reactjs.org/[React.js]).
2525

@@ -42,7 +42,7 @@ All right. So we are building our API with JSON. There are many ways to achieve
4242
aService.getUser("1")
4343
----
4444

45-
And in REST you may call a URL with an e specific HTTP request, in this case with a GET request: <http://domain.com/resources_name/uri_pattern>
45+
And in REST you may call a URL with an specific HTTP request, in this case with a GET request: <http://domain.com/resources_name/uri_pattern>
4646

4747
RESTful APIs must follow at least three simple guidelines:
4848

@@ -84,14 +84,14 @@ $ git add config/routes.rb
8484
$ git commit -m "Removes comments from the routes file"
8585
----
8686

87-
We are going to isolate the api controllers under a namespace. With Rails this is fairly simple: you just have to create a folder under the `app/controllers` named `api`. The name is important as it is the namespace we’ll use for managing the controllers for the api endpoints.
87+
We are going to isolate the api controllers under a namespace. With Rails this is fairly simple: you just have to create a folder under the `app/controllers` named `api`. The name is important because that's the namespace we’ll use for managing the controllers for the api endpoints.
8888

8989
[source,bash]
9090
----
9191
$ mkdir app/controllers/api
9292
----
9393

94-
We then add that namespace into our _routes.rb_ file:
94+
Then we add that namespace into our _routes.rb_ file:
9595

9696
[source,ruby]
9797
.config/routes.rb
@@ -131,11 +131,13 @@ Rails.application.routes.draw do
131131
end
132132
----
133133

134-
Up to this point we have not made anything crazy. What we want to to generate a _base_uri_ wich include the API version like this: http://localhost:3000/api/v1.
134+
Up to this point we have not made anything crazy. What we want to generate is a _base_uri_ wich include the API version like this: http://localhost:3000/api/v1.
135135

136136
NOTE: Setting the API under a subdomain is a good practice because it allows the application to be adapted to a DNS level. But we will simplify things for now in our case.
137137

138-
You should be concerned about versioning your application from the beginning as this will give your API a *better structure*. So when changes occur on your API you can thus propose to developers to adapt to the new features while the old ones are depreciated.
138+
You should be concerned about versioning your application from the beginning as this will give your API a *better structure*. So when changes occur on your API you can thus propose to developers to adapt to the new features while the old ones are depreciated.
139+
140+
//thus ?
139141

140142
[source,ruby]
141143
.config/routes.rb
@@ -153,7 +155,7 @@ end
153155
****
154156
You can find many approaches to set up the _base_uri_ when building an api following different patterns, assuming we are versioning our api:
155157
156-
* `api.example.com/`: I my opinion this is the way to go, gives you a better interface and isolation, and in the long term can help you to http://www.makeuseof.com/tag/optimize-your-dns-for-faster-internet/[quickly scalate]
158+
* `api.example.com/`: In my opinion this is the way to go, gives you a better interface and isolation, and in the long term can help you to http://www.makeuseof.com/tag/optimize-your-dns-for-faster-internet/[quickly scalate]
157159
* `example.com/api/`: This pattern is very common, and it is actually a good way to go when you don’t want to namespace your api under a subdomain
158160
* `example.com/api/v1`: it seems like a good idea, by setting the version of the api through the URL seems like a more descriptive pattern, but this way you enforce the version to be included on URL on each request, so if you ever decide to change this pattern, this becomes a problem of maintenance in the long-term
159161
****
@@ -182,7 +184,7 @@ Don't worry we'll get more details about the versioning later. It is time to _co
182184
$ git commit -am "Set the routes namespaces for the api"
183185
----
184186

185-
NOTE: There are some practices in API building that recommend not to version the API via the URL. That's true. The developer should not be aware of the version he is using. For the sake of simplicity, I have chosen to set aside this convention, which we will be able to apply in a second phase.
187+
NOTE: There are some practices in API building that recommend not to version the API via the URL. That's true. The developer should not be aware of the version he'ss using. For the sake of simplicity, I have chosen to set aside this convention, which we will be able to apply in a second phase.
186188

187189
We are at the end of our chapter. It is therefore time to apply all our modifications to the master branch by making a _merge_. To do this, we place ourselves on the `master` branch and we _merge_ `chapter02`:
188190

@@ -232,11 +234,11 @@ Rails.application.routes.draw do
232234
end
233235
----
234236

235-
By this point the API is now scoped via de URL. For example with the current configuration an end point for retrieving a product would be like: http://localhost:3000/v1/products/1.
237+
By this point the API is now scoped via the URL. For example with the current configuration an end point for retrieving a product would be like: http://localhost:3000/v1/products/1.
236238

237239
=== Improving the versioning
238240

239-
So far we have the API versioned scoped via the URL, but something doesn’t feel quite right, isn’t it? What I mean by this is that from my point of view the developer should not be aware of the version using it, as by default they should be using the last version of your endpoints, but how do we accomplish this?.
241+
So far we have the API versioned scoped via the URL, but something doesn’t feel quite right, isn’t it? From my point of view the developer should not be aware of the version using it, by default they should be using the last version of your endpoints, but how do we accomplish this?.
240242

241243
Well first of all, we need to improve the API version access through http://en.wikipedia.org/wiki/List_of_HTTP_header_fields[HTTP Headers]. This has two benefits:
242244

@@ -247,17 +249,17 @@ Well first of all, we need to improve the API version access through http://en.w
247249
****
248250
HTTP header fields are components of the message header of requests and responses in the Hypertext Transfer Protocol (HTTP). They define an operating parameters of an HTTP transaction. A common list of used headers is presented below:
249251
250-
* *Accept*: Content-Types that are acceptable for the response. Example: `Accept: text/plain`
252+
* *Accept*: Content-Types acceptables for the response. Example: `Accept: text/plain`
251253
* *Authorization*: Authentication credentials for HTTP authentication. Example: `Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==`
252254
* *Content-Type*: The MIME type of the body of the request (used with POST and PUT requests). Example: `Content-Type: application/x-www-form-urlencoded`
253255
* *Origin*: Initiates a request for cross-origin resource sharing (asks server for an `Access-Control-Allow-Origin' response header). Example: `Origin: http://www.example-social-network.com`
254256
* *User-Agent*: The user agent string of the user agent. Example: `User-Agent: Mozilla/5.0`
255257
256-
It is important that you feel comfortable with this ones and understand them.
258+
It is important you feel comfortable with this ones and understand them.
257259
258260
****
259261

260-
// In Rails is very easy to add this type versioning through an _Accept_ header. We will create a class under the `lib` directory of your rails app, and remember we are doing http://en.wikipedia.org/wiki/Test-driven_development[TDD] so first things first.
262+
// In Rails it's very easy to add this type versioning through an _Accept_ header. We will create a class under the `lib` directory of your rails app, and remember we are doing http://en.wikipedia.org/wiki/Test-driven_development[TDD] so first things first.
261263

262264
// First we need to add our testing suite, which in our case is going to be http://rspec.info/[Rspe]:
263265

@@ -320,7 +322,7 @@ It is important that you feel comfortable with this ones and understand them.
320322
// $ touch lib/spec/api_constraints_spec.rb
321323
// ----
322324

323-
// We then add a bunch of specs describing our class:
325+
//Then we add a bunch of specs describing our class:
324326

325327
// [source,ruby]
326328
// .lib/spec/api_constraints_spec.rb
@@ -397,9 +399,9 @@ It is important that you feel comfortable with this ones and understand them.
397399

398400
== Conclusion
399401

400-
It’s been a long way, I know, but you made it, don’t give up this is just our small scaffolding for something big, so keep it up. In the meantime and I you feel curious there are some gems that handle this kind of configuration:
402+
It’s been a long way, I know, but you made it, don’t give up this is just our small scaffolding for something big, so keep it up. In the meantime and if you feel curious there are some gems that handle this kind of configuration:
401403

402404
* https://github.com/Sutto/rocket_pants[RocketPants]
403405
* https://github.com/bploetz/versionist[Versionist]
404406

405-
I’m not covering those in here, since we are trying to learn how to actually implement this kind of functionality, but it is good to know though. By the way the code up to this point is https://github.com/madeindjs/market_place_api/commit/124873774b578af3df21136df5ee80f4d50da3bd[here].
407+
I’m not covering those in this book, since we are trying to learn how to actually implement this kind of functionality, but it is good to know though. By the way the code up to this point is https://github.com/madeindjs/market_place_api/commit/124873774b578af3df21136df5ee80f4d50da3bd[here].

0 commit comments

Comments
 (0)