This is the 8º tutorial of a complete series of building a production “NodeJS API using Express, MySQL and Sequelize”.
Full source code of this class is available at GitHub Martial Arts API Part 8
After all CRUD operation of the previous tutorial, we may have a way to show the user a meaningful error message if something bad happens. This message will be also useful for you as a programmer.
We are performing our request inside a try/catch
block, therefore we will handle the error at catch
Here is an example for our getAll()
method.
We first display…
This is the 7º tutorial of a complete series of building a production “NodeJS API using Express, MySQL and Sequelize”.
Full source code of this class is available at GitHub Martial Arts API Part 7
First of all, we will simply edit our rote so it handle every case of CRUD (Create, Read, Read By Id, Update, Delete). Each request will call a specific method in our controller.
If you forgot our drawing, you check it again to remember how helpful it is.
Before editing our controller we just need to understand where the body, query, parameters and another…
This is the 6º tutorial of a complete series of building a production “NodeJS API using Express, MySQL and Sequelize”.
Full source code of this class is available at GitHub Martial Arts API Part 6
Before starting, we will configure our MySQL database. As this is not a MySQL tutorial, we will not go deep on this subject, if you have any problems I suggest you to take a course or just google your error.
This is the 5º tutorial of a complete series of building a production “NodeJS API using Express, MySQL and Sequelize”.
Full source code of this class is available at GitHub Martial Arts API Part 5
UNDERSTANDING THE PROBLEM
Our project is not too big, but we already have 36 lines and a single endpoint. In a real application where we could have +100 endpoints our app.js
would be a really mess.
To avoid that we will structure our app in Models/Controllers/Routes. In the most informal way these will mean.
Model: A representation of our table columns.
Routes: This will tell…
This is the 4º tutorial of a complete series of building a production “NodeJS API using Express, MySQL and Sequelize”.
Full source code of this class is available at GitHub Martial Arts API Part 4
This particular class is thanks to Academind Building a Restful API with NodeJS. Awesome teacher! :)
Another thing that will be great in our project is to add some configuration headers to our application. To do so, we need to add it using express middleware, otherwise, we would need to add the same headers to every single request.
If you want to go deeper on this subject I recommend you to watch Parsing the Body & Handling CORS | Creating a REST API with Node.js.
Full source code of this class is available at GitHub Martial Arts API Part 4
This is the 3º tutorial of a complete series of building a production “NodeJS API using Express, MySQL and Sequelize”.
Full source code of this class is available at GitHub Martial Arts API Part 3
As you could see in the past tutorials, if you type localhost:8000/dojos
you will get a JSON Object with one dojo (gym).
But if you type localhost:8000/
, localhost:8000/students
or any other endpoint you will not get a meaningfull response.
It would be good to send Not Found
to the user in case he typed something we do not support, for that we are going…
This is the 2º tutorial of a complete series of building a production “NodeJS API using Express, MySQL and Sequelize”.
Full source code of this class is available at GitHub Martial Arts API Part 2
Now we will return some data in our server, for that you just need to modify a bit your app.js
file so it will look like this.
If you restart your server using Ctrl+C
(to exit) and then node app.js
(to start). Go to your browser and type http://localhost:8000/dojos
.
This is the 1º tutorial of a complete series of building a production “NodeJS API using Express, MySQL and Sequelize”.
Full source code of this class is available at GitHub Martial Arts API Part 1
Before we begin you should install the following things on your computer.
If you get stuck in any of the installation you can google it to keep going with the tutorial.
NOTE: This tutorial will cover all the API being built based…
Incluir exportação para o Excel no seu software é uma máquina muito poderosa e rápida. Para o seu cliente que gosta de Excel é só ele exportar e continuar trabalhando por lá se quiser acrescentar algo.
No código vou utilizar TFDQuery
e TDBGrid
porém você pode fazer o mesmo com qualquer TClientDataSet
ou outra maneira que você está utlizando.
A principais uses clauses são:
uses
System.Win.ComObj, Vcl.DBGrids, FireDAC.Comp.Client, Datasnap.DBClient ...;
Para o Excel é apenas a ComObj
, as outras são para os dados.
Esse código cria o Objeto Excel.Application e adiciona a primeira página do excel.
procedure GerarExcel(AQuery: TFDQuery)…
Imagina você estar fazendo uma migração de dados em MySQL e descobrir que 10.000 dados não estão com CPF, CNPJ formatados em suas respectivas mask.
Não há problema algum em armazenar os dados com ou sem mask, depende da preferência do programador. No meu caso ficou mais fácil já armazenar o CPF e CNPJ com a mask, porém em uma migração descobri que o sistema antigo fazia o contrário e por isso tive que executar alguns códigos para realizar essa formatação.
No nosso exemplo vamos trabalhar com a table pessoas.
Essa table possui o campo cpf e cnpj.
UPDATE pessoas…
Flutter and Delphi Developer at Green. Teacher at SoonClass