teleren/devto huggingface dataset:
Using Cypress for API tests
Tags: cypress, javascript, testing
Published: 2021-09-26 02:54:10

Hey, today I'm here to show you how we can use Cypress for testing APIs but, before this, I have one disclaimer for you.

> I assume you know the basics about Javascript, Cypress, and your setup, so I will just skip the setup of cypress and introductions about the technology.

In this post, I using the JSON Placeholder API for tests, but you can use any API of your preference. We are going to use [cy.request](https://docs.cypress.io/api/commands/request#Syntax) for sending requests for API, so in our requests, we will use this structure:

```cy.request(method, url, body)```

So let's start the fun

First, we need to send our request to have something for the test, right? We will the `/posts` endpoint in this case, but you can use others, no problem. I separated the test case into two parts, first I show the request body, and the second part, our tests.

```
    cy.request({
        method: 'POST',
        url: 'posts',
        body: {
            title: 'Something Interested',
            body: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
            userId: 1
        }
     })
```
In request, we are creating a post with the title _Something Interested_ in user of ID is 1. According to the documentation of [API](https://jsonplaceholder.typicode.com/guide/), the response should have four params, so now, we go check this and explore the ways _Cypress_ provides for API tests. 

```
.then((response) => {
            expect(response.status).to.eq(201)
            expect(response.body).to.have.property('id')
            expect(response.body).to.have.property('title', 'Something Interested')
            expect(response.body).to.have.property('body', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.')
            expect(response.body).to.have.property('userId')
        })
```



* `expect(response.status).to.eq(201)`: How the request is for creating a post, we need to receive a `201` status code, what is `Created`.
* `expect(response.body).to.have.property('title', 'Something Interested')`: Here we are checked if a title post is correct.
* `expect(response.body).to.have.property('body', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.')`: In this test, we are checked if a body post is correct.
*  `expect(response.body).to.have.property('userId')`: So in this case, we are verifying if in the response body the user ID exists.

In Cypress exists some other methods for test API and you can find them in [documentation](https://docs.cypress.io/guides/overview/why-cypress#API), this post was an example of what Cypress can do. The full project are in my [github](https://github.com/rodrigosta/testing-api-with-cypress), if you want to see closer.
So thank for your time and I hope it helps.
When to use Microservices
Tags: microservices, systemdesign, webdev, architecture
Published: 2021-09-26 01:38:44

---
title: When to use Microservices
published: true
description: Microservices provide several benefits, but you have to carefully analyze their pros and cons to unleash their full potential.
tags: #microservices #systemdesign #webdev #architecture
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iam8ubyeb7blwpbwsd8y.jpeg
---
> Of all the monsters that fill the nightmares of our folklore, none terrify more than werewolves, because they transform unexpectedly from the familiar into horrors. For these, one seeks bullets of silver that can magically lay them to rest.

> The familiar software project, at least as seen by the nontechnical manager, has something of this character… But, we see no silver bullet.

> Frederick Brooks

During the last decade, Microservices have been very popular. It seems that a lot of people believe they will solve each of the issues in their applications. They indeed provide several benefits, but you have to carefully analyze their pros and cons to unleash their full potential. In other words, Microservices are great, but only if you know when they make sense.

In general, every technology decision has multiple trade-offs. There’s no such a thing as a perfect solution. Almost always, you have to conform with a good enough one. Which one should be? Well, that’s one of the hardest things about developing and designing information systems. For instance, Microservices add a lot of complexity to your system to improve scalability, agility and robustness.

Bear in mind that Microservices are just a way to achieve your goals. Before adopting them, you should consider alternatives that could be less expensive in terms of costs or/and time. If you finally decide to migrate your system to Microservices, you must constantly monitor what is happening and see if you are accomplishing your goals.

I recently read a couple of books about this topic, such as Microservices Patterns by Chris Richardson and Monolith to Microservices by Sam Newman. These are great books with many considerations to keep in mind when implementing Microservices. In particular, Sam Newman wrote about a few things to consider before deciding to adopt this architecture. I find them very interesting, so let’s see what he thinks about it.

### Three questions before adopting Microservices
* What are you hoping to achieve ?
* Have you considered alternatives to using microservices?
* How will you know if the transition is working.

### Reasons to adopt Microservices
* Improve team autonomy
* Reduce time to market
* Scale cost-effectively for load
* Improve robustness
* Scale the number of developers
* Embrace new technology

### Reasons to not do it
* Unclear domain
* Startups
* Customer-Installed and managed software
* Not having a good reason
Learning Rust with rustlings
Tags: rust, learning
Published: 2021-09-26 01:03:10

So.... first thing is first

Hello again!!!!

![Welcome pal](https://media.giphy.com/media/l0MYGb1LuZ3n7dRnO/giphy.gif)

I am writing and learning while I am in a call on discord :)

So what you would be wondering now:
Q: Why Rust (lang)? Do you love your self?
A: Why not? And no... I just UwU

Now I have answered your questions, I am going to learn Rust, the programming language not the game OwO

So, I am learning the syntax here:
- https://github.com/rust-lang/rustlings/

You can install it or you use it in repl.it, read the README :D

Next... when you open the repo, you see something like this
![Files and folders](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pm611m1vy5ow20jnqkgo.png)

I've read the REAMD.md, so I know what and where things are jsjsjssjsjsjsjs

And the first thing we have to do is type `rustlings` in the terminal, if you get an error, probably you don't have the binaries in the *PATH*, so be careful!!!

So with that we get a little of information, the real problem starts with `rustlings watch` that we will use, since it makes us follow everything, from beginning.

Each time we fix (or maybe not, and we just bug it more :D), the command will display for us the error or a "Congratulation" for doing it well.

And this is everything for today :D

Have a nice sleep. With love B

![Good night](https://media.giphy.com/media/ReycznqpTfwuwefOl4/giphy.gif)

---

## Follow me!
(I liked more the red bird :_()
🐦 [Twitter](https://twitter.com/blit12_)
🐙 [GitHub](https://github.com/blitty-codes)
👥 [LinkdIn](https://www.linkedin.com/in/blitty/)

---
Code Smell 87 - Inconsistent Parameters Sorting
Tags: programming, webdev, codenewbie, functional
Published: 2021-09-26 00:17:31

*Be consistent with the parameters you use. Code is prose.*

> TL;DR: Don't confuse you readers. Keep the order.

# Problems

- Readability

- Consistency

# Solutions

1. Refactor and change parameters order.

2. Use [named parameters](https://en.wikipedia.org/wiki/Named_parameter)

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/1f21534bd7ddf9390271ed0badd7352b)
```javascript
function giveFirstDoseOfVaccine(person, vaccine) {
  //
}

function giveSecondDoseOfVaccine(vaccine, person) {
  //
}


giveFirstDoseOfVaccine(jane, pfizer);
giveSecondDoseOfVaccine(jane, pfizer);  //Unnoticed mistake
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/e33e4b69f36750d7a24621f70aba155c)
```javascript
function giveFirstDoseOfVaccine(person, vaccine) {
  //
}

function giveSecondDoseOfVaccine(person, vaccine) {
  //
}


giveFirstDoseOfVaccine(jane, pfizer);
giveSecondDoseOfVaccine(jane, pfizer);  //jane is immunized
```

# Detection

- Some very smart linters may be able to compare arguments and hint for possible mistakes.

# Tags

- Readability

# Conclusion

This is a very simple smell. 

Readability is very important to avoid mistakes.

# Relations

{% post https://dev.to/mcsee/code-smell-10-too-many-arguments-4o67 %}

# Credits

Photo by <a href="https://unsplash.com/@lg17">Lance Grandahl</a> on <a href="https://unsplash.com/s/photos/disorder">Unsplash</a>
  
{% twitter 1441462443364864006 %}

* * *

> Computers are good at following instructions, but not at reading your mind.

_Donald Knuth_

{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * *

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}
Instalando PHP no MacOS
Published: 2021-09-25 20:49:03

## Pré-requisitos

Iremos utilizar o gerenciador de pacotes do macOS, o Homebrew. Primeiramente se certifique que o Homebrew esteja atualizado:

```bash
brew update
```

...e configurado corretamente:

```bash
brew doctor
```

Como o repositório oficial do Homebrew demora muito para atualizar as versões do PHP, iremos utilizar o repositório de terceiros [@shivammahtur](https://github.com/shivammathur/homebrew-php). Este repositório nos permite instalar de forma rápida até mesmo versões betas do PHP.

```bash
brew tap shivammathur/php
```

## Instalando o PHP
Podemos instalar facilmente várias versões do PHP:

```bash
brew install shivammathur/php/php@5.6
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.0
brew install shivammathur/php/php@8.1
```

Você pode querer alterar alguma configuração do php no arquivo php.ini. Cada arquivo de configuração se encontra em sua respectiva pasta da versão, como no exemplo abaixo:

```bash
/opt/homebrew/etc/php/5.6/php.ini
/opt/homebrew/etc/php/7.4/php.ini
/opt/homebrew/etc/php/8.0/php.ini
/opt/homebrew/etc/php/8.1/php.ini
```

Agora temos a versão instalada, porém não "linkada" ao comando `php`. Para fazer esse link execute o comando:

```bash
brew link --overwrite --force php@5.6
```

Obs.: caso o comando `php` já esteja atrelado à um pacote isntalado, é necessário remover o link com o seguinte comando:

```bash
brew unlink php
```

Veja se o PHP está na versão correta:

```bash
php -v
```

Output:

```bash
PHP 5.6.40 (cli) (built: Jul  2 2020 04:41:54) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
```

#### Referências
- [getgrav.org](https://getgrav.org/blog/macos-bigsur-apache-multiple-php-versions)
- [Phil Cook](https://github.com/philcook/brew-php-switcher)
1 Tip to Double Your Productivity in Postman
Tags: postman, productivity, webdev, tips
Published: 2021-09-26 00:04:57

I've noticed when testing authenticated endpoints in Postman that every time my token expired, I needed to take a new token from my POST /authenticate endpoint and copy-and-paste it into each of my requests. This can quickly become a tedious process when your token's TTL is very short.

So I came across a quick-fix that has helped me save time by completing this process in just one click, and I wanted to share it.

##The Solution
1) Start using environment variables!

Rather than explicitly entering the value into fields, take advantage of Postman's environment variables. There are different levels of variables (see [here](https://learning.postman.com/docs/sending-requests/variables/), but I like to keep my projects organized by creating different environments.

*You can even set up for different environments (i.e. dev, sandbox, prod)*

![Add Environment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6dx3pipc3mhasn6zkpc6.png)

![Add Variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0b705wrqd83y7srhvt8.png)

To add to a field, just surround the variable name with double curly brackets: `{{token}}`.

![Add Variables to Fields](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1abrfuicmq3w6019m6pf.png)

Now all of your variables live in one place.

2) Create a post-request script

Now you can set the environment variable using a post-request script. Under the endpoint tab where you get your token (usually a POST to an authentication endpoint), click the "Tests" tab.

![Click on Tests tab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f90ekexq063euyhlgsfn.png)

This is where you can do all kinds of things (check out the snippets on the right side). However, in this case, we are just setting an environment variable. 

Add this script to the panel: 
```
const token = pm.response.json().token;
pm.environment.set("token", token);
```

![Enter Script into Panel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2l0lv7ke1t9nauopol1.png)

*Note: Your authentication endpoint response may have a different structure so make sure in Line 1 you are referencing the correct token property.*

Now any time your token expires, you just call this endpoint and the token returned will be used everywhere it is referenced (i.e. all your protected endpoints).

##Conclusion
I understand that this probably isn't the best way to do this. Please share a better solution in the comments! It would be extremely helpful for everyone. 

Also, I know that I never use Postman to its full potential, so if you have any useful tips on Postman in general, please share those as well!

---

###Thanks for reading! If you want more tech tips, software stuff, and bussin' blogs, you can throw me a follow on [Twitter](https://twitter.com/JBurroughsTech)🔥🤘🏽🐶
Do you need a State Management Library?
Tags: react, javascript, tutorial, discuss
Published: 2021-09-25 23:23:55

The other day I was browsing LinkedIn when a poll caught my eye

> What's your favourite React State Management Library and why?

![LinkedIn poll](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovbnnqrcaf8kl6gmbmqw.png)

Naturally, I felt there was an option missing from the poll and left a comment. I replied saying I felt a custom hook with the context API should be enough, let's talk about that.

## What is a State Management Library?
Before we look at what state management is we have to agree on what state is. State is a place in memory where we can store some data, anything really. For instance with a checkbox it is either checked or not, true or false, and they are its states, storing a user's name as a string is a state or an array of preferences, the list is endless.

**So what is state management?** These states/variables need to be interacted with some how. Be it reading the value or setting it. In it's most simple form state management is how you interact with a variable. 

In React, states are easy provided you only want to touch them inside the components they were made in. State Management Library's, for React, make it possible to interact with states from anywhere without having to prop drill. This is great and it why these libraries are so popular but is there a better way?

## What is the context API?
The [context API](https://reactjs.org/docs/hooks-reference.html#usecontext) is a default React hook used to allow data (objects, functions, strings, etc) to be accessed by any child component.

When we use this API in tandem with a custom hook it gets a lot more powerful. We can pass objects with `getter` and `setter` functions that can be used read or modify states, as you'd expect, or have functions that allow us to set several states at once or even give us data back in certain formats, perhaps for API calls.

### How can we use the context API?
Here I've written a very simple hook to manage storing a person's name. It stores a first and last name, which you can both get and set, it also concatenates the two names into one long name that can be read from context, this is not something you'd ever really need to do but it shows how data can be returned formatted, there is also a function that lets you set both states at once.

{% codesandbox hardcore-brattain-s67tf %}

Have a look through the code, as I said it's nothing complex but it was only meant to serve as an example of what can be done rather than a template to be followed.

## Final thoughts
With all of this power built into React do we need State Management Libraries? Maybe we do or maybe we don't but either way please let me know if you use one and if you do why? I look forward to reading your comments.

Thank you so much for reading.
CTA Button Web Component
Tags: beginners
Published: 2021-09-25 22:59:39

For my Web components class at Penn State, we have been tasked with creating a Call-To-Action(CTA) button.  So for my partner and I have some basic CSS applied to our button so we can visualize the changes in states: disabled, active/hover, and active/clicked.  In general, our project currently is just a template of everything we need to still complete.  We still need to work on the disabled state, inverted/high contrast mode, and the finalized styling to have a circular button instead of a rectangular button.

Our progress has not been without challenges though; mainly understanding the requirements for the project and understanding the Open-WC boilerplate.  My partner and I midunderstood the directions since we initially did not have a <button> tag and we tried to make a button from scratch.  Once we had a chance to meet with the professor again we realized we needed to have the tag and that immediately helped solve a lot of our issues.  Since I am still new to web components, I did have trouble figuring out where the tests, storybook, and styling of the component took place in the example.  

So far I have learned the basics of the Open-WC framework and how powerful web components are.  I now understand the directory structure of this project and how useful storybook is!  Also, web components are an example of practicing DRY(Don't Repeat Yourself) in web development. Especially in large organizations having the same look, feel, and function to web components is essential.  My partner and I still have work to do and I still have tons to learn from here the rest of the semester!
 
Link to the current element: https://github.com/3B4B/circle-button-fj
Just ship that MVP...not
Tags: beginners, codenewbie, decodingcoding
Published: 2021-09-25 22:58:25

---
title: Just ship that MVP...not
published: true
description: About losing nerve and self doubt when launching your finished projects
tags: beginners, codenewbies, decodingcoding
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4v7a7cn4tdyzhk7vsvu.jpg
---

In the book *The Artist’s Way Every Day*, author Julia Cameron talked about those moments of self-doubt when we are almost finished with our project, and just before launch, that self-critical voice ambushes you and does that thing it always does: 

> A critical failure of nerve at the last moment causes us to doubt the worthiness of projects we have birthed. Novels go into desk drawers. Plays languish on shelves. The pumpkin rots on the vine. How can we go forward from here? We must believe, first of all, in the worth of our brainchildren. We must not abandon them. We must keep them a priority. Faced with rejection, we must keep trying. At root, it comes back to being a matter of faith. We must see our work as divine in origin. We must believe there is a divine path of goodness ahead in its unfolding. When we are rejected, we must ask, “What next?” and not, “Why me?”

Indeed. 

This voice of self-doubt rears its ugly head all the time, just when I finish my rough MVP of a project. This is bad. It doesn't yet do all the stuff I want it to do. And before putting it on public domain, that voice said:

*“This is shit. Don’t embarrass yourself by putting it out in public.”*

And true enough, that self doubt would creep into how I shared and talked about it. I would be shy about sharing it, and ashamed of what it couldn’t yet do. And in typical self-fulfilling vicious cycle, the reception to the project will be cold. That would go on to make me question myself even further: did I waste a month of my time making something no one needs? Maybe I should do something else…

But reading that passage in *The Artist’s Way Every Day* was encouraging. That perhaps we all have that tendency to lose our nerve when we’re putting all of ourselves into something - our strengths and also all of our weakness, our vulnerabilities. 

And these moments of self-doubt are part of the ride. They are an important filtering process for testing if you have real faith in what you are doing. If you didn’t, then great, don’t waste your time and go on to another. If you did, then even better, you know your heart is right and you know what you have to do next. 

OK, what's next?

---

Follow my daily writings on [Lifelog](https://golifelog.com/goals/30), where I write about learning to code, goals, productivity, indie hacking and tech for good.
All About Hackathons!!!
Tags: htf, hackthisfall, vit, doubts
Published: 2021-09-25 22:49:05

Date of Event -: 25 September 2021
Time: 10:00 P.M.
Meeting Host -: <a href="https://linktr.ee/eshan1925">Eshan Gupta</a>
Topic-: All about Hackathons & doubts,counselling session.

<img src="https://www.icegif.com/wp-content/uploads/hi-icegif.gif" alt="hi">

Hey,
So this was the first event that was conducted by me at VIT, Vellore and the session/event gained approximate 60+ participants and was of approximately of 2.5 hrs.

The event was really successful according to me as I was able to clear all the doubts that students had by the end of the session. Not only this the students were also very thankful to the host for organising such a session.

Later on students demanded for two more sessions in the coming days and I being the host also definetly plan to keep these events shortly. The topics for the demanded events were-:

- Topic 1-: Introduction to Open Source and Github
- Topic 2-: Introduction to LinkedIn

<img src="https://c.tenor.com/F76vq7DKzgIAAAAC/jimmy-fallon-super-fun.gif" alt="fun">

We had a loot of fun while the event lasted and many of the attendess approached and got connected with me after the event. Really it was a very nice experience guiding so many students at one time.

The event was successfull and I also told all the students about the Importance of Hackathons and that there is not a loot of knowledge required for attending any Hackathon.Some of the other topics that were discussed during the session are-:

- Importance of Hackathons
- What is HackThisFall?
- Advantage of taking part in HackThisFall
- Doubts related to VIT, Vellore
- Tech Stacks to choose for coming years

Thats all that happened in the event and to sum up I really enjoyed conducting and handling so many people at a time.

<img src="https://c.tenor.com/qO2i2yn9saUAAAAM/peace-out-peace-sign.gif" alt="bye">

THANKYOU😎
Eshan Gupta