Build and Deploy a Backend With Fastify & Platformatic

Rate this content
Bookmark

Platformatic allows you to rapidly develop GraphQL and REST APIs with minimal effort. The best part is that it also allows you to unleash the full potential of Node.js and Fastify whenever you need to. You can fully customise a Platformatic application by writing your own additional features and plugins. In the workshop, we’ll cover both our Open Source modules and our Cloud offering:

- Platformatic OSS (open-source software) — Tools and libraries for rapidly building robust applications with Node.js (https://oss.platformatic.dev/).

- Platformatic Cloud (currently in beta) — Our hosting platform that includes features such as preview apps, built-in metrics and integration with your Git flow (https://platformatic.dev/). 


In this workshop you'll learn how to develop APIs with Fastify and deploy them to the Platformatic Cloud.


FAQ

In PlatformaticDB, generated types represent the schema of your database tables as interfaces, helping with autocompletion and reducing the need for manual schema management.

PlatformaticDB is a tool that allows you to create both Open API and Graphical schema from your database without writing any code. It's part of the Platformatic framework and can be customized using Node.js.

To check your Node.js version, enter 'node -v' in your terminal. Ensure it is version 18.18.0 or higher for compatibility with PlatformaticDB.

To start with PlatformaticDB, clone the repository, ensure Node.js is installed, and follow the setup instructions provided in the slides or the shared material online.

The setup process for PlatformaticDB involves running a generator to configure the database and environment, applying default migrations, and optionally creating plugins or generating types.

You can access the slides and materials for the Platformatic workshop by visiting the provided URL, platformatic.dev.dbungall.com, where all the material is publicly available.

PlatformaticDB uses environment variables to configure application settings securely. These variables are used to fill in configuration details without hard-coding them into the application's source code.

Migrations in PlatformaticDB are used to manage database schema changes. They help in versioning the database schema by tracking changes and applying them incrementally.

Matteo Collina
Matteo Collina
104 min
07 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Welcome to the platformatic workshop where you can create open API and graphical schema from your database without coding. The generator creates config files and types for the database representation. GraphiQL allows you to query the database and run subscriptions for real-time updates. The workshop covers creating relations, adding likes to entities, and implementing custom business logic. The back-end can be deployed to Platformatic Cloud, and there is support for API authentication and monitoring metrics. The workshop also introduces Dynamic Workspaces, SQLite benefits, and Platformatic Runtime for service composition.

1. Introduction to Platformatic Workshop

Short description:

Welcome to the platformatic workshop. We have a small crowd today, so feel free to ask questions. The slides and material are available at platformatic.dev.dbungall.com. PlatformaticDB is a tool that allows you to create open API and graphical schema from your database without coding. Make sure you are running node.js greater than 18.18.0. To get started, clone the repo or follow the slides. The workshop is incremental, and we will build an application to store and like movies. Run the command 'create platformatic' to get started.

Hi everybody. Welcome to this nice workshop about platformatic. And here you go. We have just a small crowd. So I kindly ask, if possible, if you can turn on the camera, otherwise I'm just talking to the wall. And I really don't want to talk to the wall for three hours or two or whatever it is. So talking to the wall is not nice. Thank you Jaroslav, Thank you Yusem but he's booting up and thank you Gianmarco.

Hello. Hi folks. It seems that we have a small crowd today, so happy days. And you can do things step by step, so that there is no point or no problem whatsoever in doing this stuff. And maybe a few more people are going to join in a few moments, but we'll see. Okay, so feel free to ask me questions, interrupt me anytime, hopefully if we get it done earlier than that. We'll try, okay. And that's it!

Okay? So first thing first, you can find these URLs, these slides at this URL. You will see it in here, platformatic.dev.dbungall.com. So you could take this thing and just copy it up. And I'm pasting there in the chat, too, so here you go. And you can check it out there. So everything, all the material is public, so you can just check it out.

So what is PlatformaticDB? Well, PlatformaticDB is the first tool that we shaped as part of platformatic. And it's a tool that enables you to create both open API and graphical schema from your database without having to write any code. And you can just use Node.js to customize it and so on and so forth. So, yeah, let's get into it. First thing's first, please do a safety check that you are running node.js greater than 18.18.0. So how do you do that? You do, you go, we can go back in our terminal and wait a second, yeah, close. And we can go back in our terminal and we can do node-diminusv and you should be able to get that value, something like that. Please let me know if you're stuck.

So what do we do to get started, you can go and clone this repo. Now if you're following the slide you can just click this nice button here and you can go back in your route and just pass this the topic and just run the command. Run the command. So these these things contain both the steps. It contains both the steps and the slides. So if we go and open this up you can find that we have these slides which are these ones that we just talked and those are also the value steps for setting up our application. Does it make sense? Any problem with using Visual Studio code? I do have many. I'm using Vim. I've never exited so sorry. Still the same instance. The workshop is incremental. So every step that you can find will see that you have 0-1, 0-2, 0-3, so on and so forth. Each one of those steps is actually straight forward and based upon the previous one. So you can jump through steps if you want to. Very important. If you don't need to do anything you can just do some stuff. What we're going to build will be a small application that will enable you to do some sort of sorts of APIs. Sorry an application that will enable you to store your movies and then like them. Very simple. First thing we copy these bits here and we run create platformatic. So how do we do that? Well we can run this code, we can cd and we can run create platformatic.

2. Platformatic Generator and Generated Files

Short description:

The generator creates a platformatic db.json config file with autocompletion. It also generates a plugin file and types for the database representation. These types provide autocompletion and are loaded via a global.tls file. Running the command 'Cd movie quotes apps mpm start' generates an open API documentation and graphical interface. We can interact with the API using various HTTP methods and query the database using GraphiQL. Environment variables are stored in the .env.sample file, which should be committed instead of the .env file.

Note that this says npx create platformatic latest at latest what you could do also is, do npm create space platformatic at latest. The two things are identical.

Okay and then it prompts some questions and here are some of the answers that we are going to do. We are picking DB, we are creating in this folder. We want to create a default migration, create a plugin maybe. Yes, and don't you know TypeScript port and we want to run npm install. Then we want to apply the default migrations and we also generate the types. Come on. And we skip the GitHub actions, we are not going to create a repo for this. Okay.

Were you able to run the generator? Yes, I was able. I just wanted to ask what are the migrations, what are these generated types if you're not using TypeScript? Oh, yes. I'll show that in a moment. Okay. Let me show you. So first of all, what files it generated is for us. So it generated us a platformatic db.json. This is our config file. Note that our config file is, sorry, it's, you see that it has full autocompletion. So you will see, you will be able to autocomplete the values with Visual Studio Code 2 using the same language server. It uses environment variables to fill things in, so it's automatically completed. What are the types? So you see here that it has a plugin file, which is essentially these, which is a Fastify plugin. We'll talk about that in a moment. The types can then be used for the representation of our database, so in fact it includes all the properties. So for example you can see that you have a movie here has an idea in the title, which is the content of the default migration. So it automatically creates for each table, it automatically creates an interface for each one of our table so that you can avoid some time. Does it make sense? Yeah, yes, thank you. And all of those are loaded via this global.tls file and which then is loaded here as part of the plugin. So you could then use those types in this JavaScript file and we'll talk about that in a moment. Essentially they're there to provide autocompletion. Do you like autocompletion? Who doesn't like autocompletion?

So let's start the thing. What we can do? Cd movie quotes apps mpm start. What has this generated us? It has generated us an open API documentation and graphical. We can open up those two links. Taking a look at the first one, you can see that it has get, post, put, and all the things that we would expect it to be. These are essentially just normal stuff, the normal things that you can imagine. We can run a SlashRequest and you see it's an empty array. We could potentially put post. Where is it? Post. Post in there a movie, like for example Harry Potter. And it has stored it with ID 1. And then if we go back to the top and run the query again, you will see that we got Harry Potter. Then we could actually do the same using GraphiQL. So for example, you could do a query like movies and title, and it works the same. Hey, we are at this URL right now. And you can follow the slides earlier than that. Note that we have here, we have the environment variables, OK? Where is platformatic fill in those environment variables from? We have two files here. One is.env, one is.env.sample. Do not commit your.env file but commit your.env.sample file. Why you need to commit that one? Because this is typically personal information.

QnA

Watch more workshops on topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura
Node.js Masterclass
Node Congress 2023Node Congress 2023
109 min
Node.js Masterclass
Top Content
Workshop
Matteo Collina
Matteo Collina
Have you ever struggled with designing and structuring your Node.js applications? Building applications that are well organised, testable and extendable is not always easy. It can often turn out to be a lot more complicated than you expect it to be. In this live event Matteo will show you how he builds Node.js applications from scratch. You’ll learn how he approaches application design, and the philosophies that he applies to create modular, maintainable and effective applications.

Level: intermediate

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Node Congress 2022Node Congress 2022
26 min
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Top Content
Do you know what’s really going on in your node_modules folder? Software supply chain attacks have exploded over the past 12 months and they’re only accelerating in 2022 and beyond. We’ll dive into examples of recent supply chain attacks and what concrete steps you can take to protect your team from this emerging threat.
You can check the slides for Feross' talk here.
Towards a Standard Library for JavaScript Runtimes
Node Congress 2022Node Congress 2022
34 min
Towards a Standard Library for JavaScript Runtimes
Top Content
You can check the slides for James' talk here.
ESM Loaders: Enhancing Module Loading in Node.js
JSNation 2023JSNation 2023
22 min
ESM Loaders: Enhancing Module Loading in Node.js
Native ESM support for Node.js was a chance for the Node.js project to release official support for enhancing the module loading experience, to enable use cases such as on the fly transpilation, module stubbing, support for loading modules from HTTP, and monitoring.
While CommonJS has support for all this, it was never officially supported and was done by hacking into the Node.js runtime code. ESM has fixed all this. We will look at the architecture of ESM loading in Node.js, and discuss the loader API that supports enhancing it. We will also look into advanced features such as loader chaining and off thread execution.
Out of the Box Node.js Diagnostics
Node Congress 2022Node Congress 2022
34 min
Out of the Box Node.js Diagnostics
In the early years of Node.js, diagnostics and debugging were considerable pain points. Modern versions of Node have improved considerably in these areas. Features like async stack traces, heap snapshots, and CPU profiling no longer require third party modules or modifications to application source code. This talk explores the various diagnostic features that have recently been built into Node.
You can check the slides for Colin's talk here.