Intro to Elixir | Lessons 20: Project set up

Elixir
Transcript

English (Auto-generated)

Hello Friends. Thank you for continuing. And today we're gonna go through less than 20 and we're going to learn how to set up projects with elixir so far we've learned how to do things in a simple file or maybe two files. Now that's not practical in real life because usually your project will need some structure. You need ways to structure your files, you need ways to use different modules in other modules and we'll see how we can do this and also we need to know how we can test our code. It's very important that we have tests written so that we could always run the test to make sure that our code continues to work. So for this series what we're going to do is we're going to integrate with this ap I hear um reason why because you know almost every application web or otherwise. Usually these days it includes integrating with some type of an ap I http based Api so we're gonna use this one here. It's a bit of a fun api it actually called the Star Wars api what it does, you make requests for example you make a request to the CRL and then once you get back you get back this Jason format with some information. So for example, you know I'm sorry if you're not a Star Wars fan but I think you'll get the idea here regardless. Is that for example if you're fetching information about people want and you get information about luke Skywalker and this is all the information related to that person. So if you go something like people to do request, we get C. Threepio and then you get the information about them. So we're gonna build some fun things to integrate with this Api So we'll make requests and we'll get the responses and we will see how we can handle those responses from the api. Again it's not a practical real life projects that said it's the closest as it can get because you know, chances are you will need to integrate with some sort of an aPI. So to start an A. P. I we're gonna use something called Mix. Mix is a command that gets installed when you install elixir, so you don't need to install anything extra for Mix. So you type here Mix and then you type new and then let's call this Star Wars and this generates a scaffold of an application that includes a boilerplate files that we will need. And I will go ahead and explain to you the folder structure. So right here this is the folder right here. And um actually before I go there maybe I'll just add some notes for you to remember. So I will go and I will write in your note that we will be integrating with the Star Wars E. P I and um to learn how to handle api integration with Alexa. Uh on the way by the way we're going to learn many different things we haven't learned already. So you know highly encourage you to continue with me and walk through the project because we will I will be introducing new concepts that we haven't seen before. So I'm gonna start here. So every every um project comes with a read me file. So here we can say ap I integration intro to elixir courts, we can just delete this one right here. Um Now Star Wars that does come um with with some some gems but we're what we're actually going to do. So if you go to documentation, if you go to um you know, there's actually an elixir library that helps integrate with it that said I will do just very simple like see there's this swampy ex that said, what I'm going to do is I'm going and as you can tell it's pretty outdated. But more importantly, I'm going to just use a simple HTTP library because you may encounter some a p I S. An elixir that don't have their own libraries built. Alright. So this is here, basically just you can think of it as just to read the file, we will integrate with the Star Wars FBI for fun. Okay. And this is an important um file that you're gonna see right here. So this is the file that we're going to encounter going forward and uh this file right here is called Mixed Mixed file defines how you're going to compile how you're going to build your project. It also defines How you're going to uh you know, the libraries you're going to include with it, you know, for instance, here you're we're defining here that we're using electric version 1.11. Again, if you're upgrading elixir later you can change it right here. Um it is setting the default to be proud, which is production. Again, it's not a huge deal in our particular case here because we will be um just have this app for fun. Um that said you could have different files depending on whether like for for development for tests and for production but for our purposes here this is fine. You can define the version as well. Again, I'm not going to change this that the app name too. And then finally here you basically define what are the dependencies. So dependencies here are external libraries that we're going to be using in our applications. So you also define here by the way, if you need to run external applications, like for example, some libraries coming with certain applications that you may want to integrate with. So I'll keep it as it is for now. And for the depths here we're going to actually use some libraries to help us make http requests. Right? So we don't have to reinvent the way all the way from scratch so that's why we're going to encounter using these depths but I'll leave this for um the next lesson, I'm keeping it today, like just so we could get the project set up and then we could do we could do more in the next lesson. Um So a lot of the code we will right here so oh sorry before I before I go to those folders let me tell you what the other files here. So this file here dot get ignore if you're familiar with yet. It's basically a standard get ignored file which tells get what files to actually ignore not to have them committed to get there's default ones right here but in case you want to add more, feel free to add um This is especially important if you have integration with a P. I. S. And then you wanna put some sensitive data like passwords for example then you will really need to ignore anything that includes sensitive data. Again I'm not gonna touch it for now. We're not gonna need to do anything for this particular one and then you get the four matter here for matter. I'll show you later. Maybe this is one of the early things I will show you here. So um let's let me go to the library here. This is a very simple Star Wars module that have a function called Hello that just returns an atom that is world. Okay so just to show you how we could use mix in the project let's say I invent this really poorly by having a deeply invented what I can do. I can go to the folder where my project lives and I can put mixed format after I run it. Notice how the format er automatically brought this to the proper indentation for matter is a really nice way to auto format your code. It's, I mean most, even though most editors, I'm using visual studio code here, but most editors, as you hit, enter the auto indent based on your preferences, sometimes you may forget, you may double intent or you may add an extra space. Running a mixed format will do it. So this for matter, you can basically uh you know, can figure what you want to format and how you want to format also, you could, you know, formatting um depends on the style that you're using or that your company is using. So it's not universal for all um for all electra projects. So there's a starting for matter here but you could you could do your own configurations here as well. So this is gonna basically format as a config which we don't have right now and then but you know, a bigger project will probably have a config folder. It will also configure lib and test and anything inside them that have the extension E X or E X S. So which brings me here to an important thing here, which is test. So you notice we have test files, I won't go to the details into them because I will have a dedicated lesson for tests but the only thing I want to explain now is notice that uh there's files here that ends with E X. And then other ones that ends with E X S. So any excess also include electric code. But think of them more like files that are kind of run on demand, like like script files, elixir, script files that don't get compiled so they're not part of your core package, your core compiled file. Remember how elixir compiles the code into the beam which is airline based. You don't have usually to worry about this, it gets compiled for you but anything with the X. S. Doesn't get compiled, so it's only used for files that you want to run to accomplish a particular purpose, like a script or in this case the test which is a script. So when you want to test your file, you run those but you want to go live with your application, you don't necessarily need your test to be packaged because on production you do not really want your tests to be with your file. They're just gonna add deadweight basically to your application. So the ones that get compiled are the X files and the E X s. Don't get compiled with your main application. That's the one thing I want you to remember right now. So we're starting here. So a lot of the code we're going to write will be in the lip. So we're gonna write stuff in the lip. And in conjunction we're gonna write tests in this test folder. And then when we're going to add new libraries, we're going to basically added in this depth section into this mix. E X S. Okay. So this is roughly what I want you to focus on now. So we're gonna use mostly mixed tests and lip and, yep, that's it for now. Um Let's start working on those in the next lesson. Sure.
190 Views 0 Likes 0 Comments

We set up the project we will be working with for the next number of lessons. We will be integrating with the StarWars API https://swapi.dev/

Comment
Leave a comment (supports markdown format)