2026-09-10 11:52
Status:
Tags: IBM IBM Full Stack Software Developer Professional Certificate IBM Application Development using Microservices and Serverless APIs REST API Back End
ADMS - Module 2- Web API Essentials REST API and GraphQL
==Web API Essentials: REST API and GraphQL
-
What is REST?:
- REST stands for Representational State Transfer
- It is basically a way of sharing stateful data between different programming endpoints, allowing for communication between different services that remember user data and interactions
- There is also then RESTLESS APIs, which in tandem are a way of communication between non-stateful applications or ones that do not remember user data and interactions, and treat each new request as brand new
- You can generally use REST APIs as ways for communication between different services in your application, like one route for your backend and one for your front end, allowing the two of them to communicate with each other about user requests, usually doing so with JSON
- REST APIs use HTTP for communication, and send over the different CRUD (Create, Read, Update, Delete) requests between the two API endpoints
- This is generally used in order to update the state of one of the given applications, so think for the MidasCloud for example, you have the login application which out have the backend update the user database for authentication, which would be a REST API
- The actual API values are stateless, and therefore all of the actual communication values are inside of the API request itself, and there is no added information, although the services they might communicate with might have state
- REST APIs are stateless, but used to communicate state between applications
- This makes them very scalable, but then also gives the a Uniform Interface, meaning that their request for given data looks the exact same regardless of the origin it is coming from
- This means that one identifier is equal to one Uniform Resource Identifier (URI)
-
Introduction to API Gateway:
- An API Gateway i think can generally be though of as this thing that sits between the actual client and then a large collection of backend services
- It then basically would get a given request from the client, and then redirect it over to a given backend service based on the origin or nature of the request, sort of like the whole routing ordeal really
- Why would you use one?
- Its create because it centralizes your APIs, meaning you can rate limit certain ones by denying access to a given user for them, saving you resource power and preventing DoS attacks
- It also acts as a centralized hub for the analysis of your API usage, letting you bill for them as well
- It also makes it really good if you want to make changes to your APIs, allowing you to change them in and out as you so generally please
- For example, if you have a given Online Store project or something like that, for the different microservices you would have different backend APIs that a user can access to do different things
- This includes things like:
- A Production Information Service
- An available Inventory Service
- An Order Service
- An authentication and account creation service
- This can be a lot of different applications for you to have an API access for, especially for a given stupid user
- This therefore, means that you can use an API gateway in order to centralize access to each of these backend services, and allow for you to do things like change the host for each service if need be, and let you also scale each service up and down very easily, replacing them if need be
- This way the access for the user is not changed at all
- This is generally good for the fact that it makes it easier on the user to operate with your application, they do not need to know about how your actual implementation works in order to use your site, they just use it
- It also basically means that there is a minimal source of incoming requests into a single stream, which is good for monitoring, and allows for less backend requests since MULTIPLE REQUESTS can be done in one go using the API Gateway
- Lastly, you have full control over the entire gateway, allowing you to know what is going on and how the world sees your services
- The drawbacks is this is another layer of complexity to your application, requiring configuration as well as maintenance
-
Creating REST APIs:
- Basically the best way in order to set up your own REST APIs, is just to write in a backend like i would have done inside of the MidasCloud login for the portal
- Basically, the API is just the point of routing that you would have in any real backend application, where in which you would have something that is running and listening to given requests on a given HTTP port
- This would then have access to all of the needed services that your application would need, like a database or authentication services or whatever else you would have
- Using this, you could then basically take incoming requests on certain routes, and then proceed to send back information to the front-end or whatever is hitting those back-end requests
- The thing is that those things are in fact open to the internet whenever that service is running, so your service is open on that given port (as long as the internet can see it), and so ANYONE can send over information on those specific routes and ports to your machine
- Generally this is okay, as they would be hooked up to your front-end, but if you have an API that you make that you would like for other people to use, then that is exactly how they would do it, by connecting to your server backend which is running on a given port, and hitting it with HTTP requests
-
Making API Requests using CURL and Postman:
- cURL short for Client URL, is basically a linux tool that allows you to send over a multitude of internet protocols over your own local network or an outside network using the terminal
- Its basically a terminal tool that is able to transfer data with URLs, generally something like
curl https://localhost:3000or something like that, to hit the 3000 port on your given device - The above command is good for a regular test to see if something is working, but you can also actually send data over using cURL as well, which is good for things like endpoint testing or debugging in your API/backend programs
- An example would be something like
curl -X POST http://localhost:3000/yourApiEndPoint -H "Content Type: application/json" -d '{"username":"MyUser", "password": "TestPassword"}', where you basically send a post request to that given route following the added information which was specified as the type of json, and then the json payload - You can also use cURL in order to download files from the internet as well
- Postman is then an API platform for the actual building and the usage of APIs, and it serves to simplify the lifecycle of each step in the process of creating and maintaining an API
- it is good because it comes with a bunch of different tools that streamline collaboration and functionality with an API, making the creation of one much easier and much faster
- This makes it a very popular choice for the actual testing and choice for testing out different APIs
- It can generally take a bunch of the same internet request types like cURL can (HTTP, HTTPS, FTP, etc), and then also convert the API to code for languages like js or python
- Postman is used with WhatsApp for example
- You can download postman for your desktop, or create an online account to use it through the web
- You can then manage all of your requests and other such things through their website
-
Documenting and Testing REST APIs with Swagger:
- Basically, your API is a communications channel that is used to communicate between two different endpoints in a piece of software
- Generally, this means you make your endpoint, and then have to right documentation that would describe how you should use your API and the nature of how it works and what not right
- Swagger then basically, is a tool that allows for easier documentation of your API by basically having it adhere to a bunch of different rules called the OpenAPI specification
- It basically runs your api through a bunch of tests of well known API use and structure, and then writes the documentation for you so that way other machines or people can use it easily
- On top of this, it builds an inherit UI that you can use to interact with or modify your own API, which then also allows you to change and customize that UI with a json configuration file
- OpenAPI specification generally, an API was originally not meant to be self-serviced, but instead be data driven and what not
- Now, as things changed the OPENAPI initiative was basically created in order to create this language-agnostic, human/machine readable interface for RESTful APIs
- It basically allows for you to know how to use the API and how it works without needing to see the source code itself, meaning you can effectively share and use the tool
- It sets up the different specifications that your API should follow, that being the different operations your API should support, the different parameters it can take in and output, as well the authentication requirements for its use
- You can then basically use swagger to sort of automatically do this for you, at least with the use of flash using the
pip install flask-swagger-uicommand, which lets you visualize the different output and interactions of your rest APIs - You need a route to server your static
swagger.jsonfile in order to actually host your UI as well, so whenever you hit the/swagger.jsonfile, you can then view your UI
-
Basics of GraphQL:
- Basically
GraphQLis a query language that is specifically made for use with an API, and allows for your clients to fetch only what they would need from your given server endpoint - GraphQL is also language agnostic, and therefore can be used in multiple different backend services
- This means that a person does not actually get any data that they do not need, and also do not
under-fetchand are able to get all of the needed data, even if it is from multiple sources - It requires just one endpoint to retrieve everything you require
- It seems you basically just instead of say having something like ports and what not, then you basically separate everything out by queries or ideas or something with a given name attached to them, allowing the person to get only that data specific item
- Different types of terms relevant are
- Query: which is basically like a get request inside of your data, it fetches whatever information is requested
- Field: which is the fields in given objects, and can be things that you would query for, so things like an ID, a name, a price, and all of that
- Mutation: which is basically like a POST request inside of a standard API, and allows for you to modify data or change it given client input
- Basically
==Summary
- REST APIs provide flexible but uniform interfaces between components
- REST APIs are stateless and scalable
- REST APIs communicate using HTTP methods POST, GET, PUT and DELETE
- REST is an architectural style defining how applications communicate
- API Gateway is the door to your backend services while also enabling you to plug additional services while providing unified access
- API Gateway makes it easier to scale or replace your backend services
- Flask is a micro web framework to host Python web applications
- cURL is used for transferring data with URLs and can be used at a command line or in scripts
- Postman is a simple and popular tool for building, testing, and using APIs
- Swagger helps you document and test your API
- OpenAPI specification is a standard way of representing your APIs
==Glossary
| Term | Definition |
|---|---|
| API Gateway | API management tool that sits between a client and a collection of backend services |
| CRUD | Creating, reading, updating, and deleting records |
| cURL | A command line tool and library for transferring data with URLs |
| DELETE | Request to delete a record |
| Flask | A micro web framework that does not require particular tools or libraries |
| GET | Request to retrieve a record |
| GraphQL | A query language that enables you to retrieve exactly what you need from the API |
| OpenAPI | specification Defines a standard, language-agnostic interface to RESTful APIs |
| pip | Python package manager |
| POST | Request to create a record |
| Postman | An API platform for building and using APIs |
| PUT | Request to update a record |
| REST | Representational State Transfer |
| Stateless | Means each request contains all the information required to process it |
| Swagger | Allows you to describe the structure of your APIs so that machines can read them |




