Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Backend Special : Building a RESTFUL API from S...

Backend Special : Building a RESTFUL API from Scratch

Avatar for Efereyan Karen Simisola

Efereyan Karen Simisola

December 05, 2020
Tweet

More Decks by Efereyan Karen Simisola

Other Decks in Technology

Transcript

  1. A little about me • Empathetic software developer passionate about

    using code to solve human problems. • I like to share my perspective on things as a beginner via technical writing and podcasts. • I am actively looking for my first technical role. • Fun-fact : I love to cook. If we ever meet, don’t ask me to buy you coffee. Ask for a steaming plate of my signature 7-spirited yam porridge. • I’m the youngest speaker at this conference. Oh yay!! • Find me online at https://karenefe.netlify.app
  2. TALK AGENDA 1. Introduction to APIs (The What’s and Why’s)

    2. Architectural styles for Designing APIs (SOAP vs REST vs GRAPHQL) 3. Tooling and Setup (Visual Studio Code, Postman, Robo3t, Expressjs, Mongoose and so on) 4. Deep Dive into our articles API ( Let’s Create Our Basic Server) 5. Http Verbs and Route Handling for APIs 6. Testing all our endpoints via Postman 7. Summary (Ask Me Questions)
  3. What are APIs ? Short for application programming interfaces, an

    API is a computing interface that defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow. An API is a set of commands, functions, protocols and objects that programmers can use to create software or interact with an external system Tip APIs are .user interfaces for developers to access resources on the internet
  4. Why Use APIs ? 1. Abstraction at its peak :

    The use of APIs abstract from users(developers) the rather boring and unimportant behind the scene processes and focuses on data retrieval. 2. Easily Accessible : With Specific Reference to Web APIs that use the HTTP protocol to communicate, nearly all programming languages can be used to access them, sometimes with the use of specialized tools. 3. Reliable : Often times, large and very well trusted companies provide API for users to access their data. Because millions of users depend on the API, it is highly reliable e.g Github API Tip Using APIs promote extensibility, accessbilty and creative thinking
  5. ARCHITECTURAL STYLES FOR DESIGNING APIS Just as there are different

    architectural styles for designing buildings, e.g, the baroque Gothic and neo-classical architectural styles, there also exists several architectural styles that can be used to design APIs, viz: • REST : Currently, the most popular and dominant architectural style for designing APIs • GraphQL : This is a pretty new option that is gaining traction due to its ability to use a single query to fetch the required data across multiple resources • RPC (Remote Procedure Call) : Another architectural style for designing APIs • Falcor : It introduces a virtual layer that can be used to map frontend requests to backend services. • SOAP : A pretty popular option, it follows the RPC style and exposes procedures as central concepts
  6. REPRESENTATIONAL STATE TRANSFER (REST) is a software architectural style that

    defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the internet. RESTful Web services allow the requesting systems to access and manipulate textual representations of Web resources by using a uniform and predefined set of stateless operations. by Wikipedia
  7. ROY FIELDING The guy who introduced REST (as part of

    his phd thesis) Read more about the principles he put up for RESTFUL APIs here
  8. HOW TO MAKE AN API RESTFUL REST proposes a set

    of rules or guiding principles that web developers could follow when building their APIs. Web APIs that conformed to those rules or guiding principles could be referred to as RESTFUL APIs. The two most important of these rules are : 1. Use HTTP Request Verbs 2. Use Specific Pattern of Routes and Url Endpoints
  9. USE HTTP REQUEST VERBS HTTP REQUEST VERBS MEANING GET Read

    data POST Send or insert new data PUT Update data in its entirety PATCH Update only a part of the data DELETE Delete data
  10. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/jane-doe GET

    Fetches all articles Fetches article on jane-doe POST Creates a new article PUT Updates the article on jane doe PATCH Updates the article on jane doe DELETE Deletes all articles Deletes the article on jane doe
  11. SOFTWARE PREREQUISITES ❏ Visual Studio Code : This is a

    great Integrated Development Environment and will be used to write all the code in this presentation. Other great options are brackets, sublime text and atom. ❏ Postman : It is a collaboration platform for API development. With specific reference to the API developed in this presentation, only GET requests can be made via the server. All other URL endpoints will be tested via Postman. ❏ Mongodb : For persisting all our data for the articles API, we shall be using Mongodb which is a general purpose, document based distributed database built for modern application development. ❏ Robot 3t : Formerly called robomongo, Robot3t is the professional graphical user interface and IDE for a more intuitive interaction with mongoDB. ❏ Nodejs : This is a JavaScript runtime environment. It allows us to run Javascript inside our code editor. It also comes bundled with its own package manager(NPM) that will be used to install third-party dependencies in our code,
  12. 1. SETTING UP OUR SERVER • Create a new folder

    called articles-API in any directory of your choice. • Initialize the folder as a Nodejs server. Using the command ```npm init -y``` should do the trick. The -y flag just says yes to all default values. You can always change the values later in package.json. • Install the following third party libraries using npm, bodyParser, mongoose, express. • Create a file called server.js which will be our entry file and will store all our server code. • Add the default server code. • Setup Mongodb by creating a new database with the name of articlesDB, a new collection with the name of articles, and a new document with two fields, title and content
  13. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/ID GET

    Fetches all articles Fetches article with id POST Creates a new article PUT Updates the article with id PATCH Updates the article with id DELETE Deletes all articles Deletes the article with id
  14. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/id GET

    Fetches all articles Fetches article with id POST Creates a new article PUT Updates the article with id PATCH Updates the article with id DELETE Deletes all articles Updates the article with id
  15. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/id GET

    Fetches all articles Fetches article with id POST Creates a new article PUT Updates the article with PATCH Updates the article with id DELETE Deletes all articles Updates the article with id
  16. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/id GET

    Fetches all articles Fetches article with id POST Creates a new article PUT Updates the article with PATCH Updates the article with id DELETE Deletes all articles Updates the article with id
  17. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/id GET

    Fetches all articles Fetches article with id POST Creates a new article PUT Updates the article with id PATCH Updates the article with id DELETE Deletes all articles Updates the article with id
  18. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/id GET

    Fetches all articles Fetches article with id POST Creates a new article PUT Updates the article with id PATCH Updates the article with id DELETE Deletes all articles Updates the article with id
  19. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/id GET

    Fetches all articles Fetches article with id POST Creates a new article PUT Updates the article with id PATCH Updates the article with id DELETE Deletes all articles Deletes the article with id
  20. Specific Routes and Url Endpoints HTTP VERBS /articles /articles/id GET

    Fetches all articles Fetches article with id POST Creates a new article PUT Updates the article with id PATCH Updates the article with id DELETE Deletes all articles Deletes the article with id
  21. AND IT'S A WRAP…….. You can access the complete code

    at : https://github.com/KarenEfereyan/articles-API
  22. Contact Me • Twitter : EfereyanK • Linkedin : https://linkedin.com/in/KarenEfereyan

    • Website : https://karenefe.netlify.app • Github : https://github.com/KarenEfereyan • Instagram : KarenEfereyan