Skip to content

Commit 2e8dabd

Browse files
corrected
1 parent a53dc82 commit 2e8dabd

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ app.listen("4000", () => console.log("Server is running on port 4000"));
314314

315315
6. The following code is an example of a very basic route. <br /><br />
316316

317+
<b>
317318
var express = require('express')
318319
var app = express()
319320

@@ -322,63 +323,82 @@ app.get('/', function (req, res) {
322323
res.send('hello world')
323324
})
324325

326+
</b>
327+
325328
7. Mostly there are two way method for roting Get and post but it is allowing All also.
326329

327330
8. <b>Route paths</b>
328331
a. Route paths, in combination with a request method, define the endpoints at which requests can be made.
329332
b. The characters ?, +, *, and () are subsets of their regular expression counterparts
330-
c. The route path will match requests to /contacts. <br />
333+
c. The route path will match requests to about. <br />
331334

335+
<b>
332336
app.get('/about', function (req, res) {
333337
res.send('about')
334338
})
339+
340+
</b>
335341

336342
9. This route path will match acd and abcd. Either b or not.<br />
337343

344+
<b>
338345
app.get('/ab?cd', function (req, res) {
339346
res.send('ab?cd')
340347
})
348+
</b>
341349

342350
10. This route path will match abcd, abxcd, abRANDOMcd, ab123cd, and so on.
343351
front (ab) and last(cd) and in between any random text you can put.<br />
344352

353+
<b>
345354
app.get('/ab*cd', function (req, res) {
346355
res.send('ab*cd')
347356
})
357+
</b>
348358

349359
11. This route path will match abcd, abbcd, abbbcd, and so on. You can place mutiple time b.<br />
360+
<b>
350361
app.get('/ab+cd', function (req, res) {
351362
res.send('ab+cd')
352363
})
353-
364+
</b>
365+
354366
12. <b>Route parameters</b>
355367
Passing the parameter on Route URL
356368
You need to define the Route URL like below.
357369
Input http://localhost:4000/users/50
358370
output {"userId":"50"}<br />
359371

372+
<b>
360373
app.get('/users/:userId', function (req, res) {
361374
res.send(req.params)
362375
})
363-
376+
</b>
364377

365378
13. If you want passing value whould not mandatory than you can use<br />
379+
380+
<b>
366381
app.get('/users/:userId?', function (req, res) {
367382
res.send(req.params)
368383
})
384+
</b>
369385

370386
14. You can pass the mutiple paramnter on route URL as like below.
371387
Input http://localhost:4000/users/50/books/5
372388
Output {"userId":"50","bookId":"5"} <br />
373389

390+
<b>
374391
app.get('/users/:userId/books/:bookId', function (req, res) {
375392
res.send(req.params)
376393
})
394+
</b>
377395

378396
15. You can seperate the parameters also by using -
379397
Input value for that http://localhost:4000/flights/hyderabad-Cg
380398
output {"from":"hyderabad","to":"Cg"} <br />
381399

400+
<b>
382401
app.get('/flights/:from-:to', function (req, res) {
383402
res.send(req.params)
384403
})
404+
</b>

0 commit comments

Comments
 (0)