Concepts in Focus
- SQLite Methods
- get()
- run()
- Node JS Third-party packages
- Nodemon
- GoodReads API
- Get Book
- Add Book
- Update Book
- Delete Book
- Get Author Books
1. SQLite Methods
The SQLite package provides multiple methods to execute SQL queries on a database.
Some of them are:
- all()
- get()
- run()
- exec(), etc.
1.1 get()
The
get()
method is used to get a single row from the table.Syntax:
db.get(SQL_QUERY);
1.2 run()
The
run()
method is used to create or update table data.Syntax:
db.run(SQL_QUERY);
2. Node JS Third-party packages
2.1 Nodemon
The Nodemon is a tool that restarts the server automatically whenever we make changes in the file.
Installation Command:
Note
- The-gindicates that the nodemon will be installed globally in the environment.
- While executing the file, replace the node with the nodemon. For example, nodemon index.js.
3. GoodReads APIs
- Get Book
- Add Book
- Update Book
- Delete Book
- Get Author Books
3.1 Get Book
We can use
/books/:bookId/
as a path to identify a single book resource, where bookId
is a path parameter.For example,
In
http://localhost:3000/books/1/
, the bookId
is 1
.JAVASCRIPT
Note
Any string can be used as a path parameter.
3.2 Add Book
To add a book to the Database, you need to send a request body in JSON format.
The
express.json()is used to recognize the incoming request object as JSON Object and parses it.The
request.bodyis used to get the HTTP Request body.
JAVASCRIPT
The
dbResponse.lastID
provides the primary key of the new row inserted.3.3 Update Book
We can use
/books/:bookId/
as a path to identify a single book resource, where :bookId
is the path parameter.For example,
http://localhost:3000/books/1/
.JAVASCRIPT
The
request.params
provides the parameters passed through the request.Note
The strings sent through the APIs must be wrapped in quotes.
3.4 Delete Book
JAVASCRIPT
3.5 Get Author Books
JAVASCRIPT