The Everyday Life of an HNG Intern; Isaac Ojerumu’s Story.

zadazini

Zada_Zini

Posted on December 2, 2022

The Everyday Life of an HNG Intern; Isaac Ojerumu’s Story.

Task 2
Create a (post) API endpoint that can carry out the operation.
An endpoint is like a calculator
In this article, I'll be bringing to light the step-by-step process involved in setting up a (post) API endpoint.

Image description

The image above is the framework of the task that Isaac carried out.

Line 3: Defines the header for the API to strictly receive JSON data.
Line 4: This is a function in PHP that is used to read the contents of the file. It is also used to make HTTP requests. In this text, the code reads the file coming in from the API.
Line 5: This decodes the API's request.
Line 7-9: These lines of code are conditional statements, that is, if this comes up, do this or that. It checks for empty requests. If any request is empty, the Slack username, the result, and the operation would be sent back empty.
Line 10: This line returns the Slack username, result, and operation type if empty.
Line 13-15: Assigns the request from x and y to the variable;

 $r_type, $r_x, $r_y
Enter fullscreen mode Exit fullscreen mode

Line 17-29: This is a control statement. It checks for the operation type and enables the programmer to perform different actions based on different conditions. Say, for instance, if the operation type is addition, it will perform an addition operation between x and y. The same goes for subtraction and multiplication.
Line 31: This returns the final result if any of the conditions I have stated earlier are met.
Line 34: This final line returns a JSON response of the report.

I have spelled out the entire process involved in carrying out the task. Fully accomplishing this task takes interns to the next stage; stage 3. As you've noticed, the higher an intern goes, the tougher it gets. This is where the principle of hard work, passion, and consistency in the Tech field comes in.
Again, I hope that you find this educative and inspiring.
See you in the next episode.

Link to the next episode: https://dev.to/zadazini/the-everyday-life-of-an-hng-intern-isaac-ojerumus-story-2j0j

💖 💪 🙅 🚩
zadazini
Zada_Zini

Posted on December 2, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related