This past week in class, we were working on a homework assignment on REST APIs. In the first part of the homework, we had to create new endpoints for the inventory path. The part I struggled with was writing the query parameters. I was pretty confused and felt like I was going in headfirst to something I didn’t understand. I found a site that explains the API’s parameter syntax to help.
For path parameters, the name of the parameter is the same as the one in the path.

For query parameters, the name is not in the path and can be anything.

The body of the parameter is the exact same. It needs a name, a declaration of if it’s a path or query parameter, if it’s required, a description, and the format of the input.
After reading through the site, I realized I was over-complicating it, and all I had to do was use the same format as the already created parameter bodies and alter it to what I needed.
————————————————————————
The next part of the homework assignment was to use GET methods to filter for results. I did not end up completing this part of the assignment, but I was still curious on how it worked. I found a site that explains all the ways you can filter for results, like having an attribute be equal, less than, or greater than a value.
To filter for an attribute with a specific value, use this line:
GET /path-name?attribute=value
You can link filters with an &:
GET /path-name-1?attribute-1=value-1&attribute-2=value-2
Less than, less than or equal to, greater than, and greater than or equal to is achieved by the shorthand lt, lte, gt, and gte, respectively. Greater than would be shown like this:
GET /path-name?attribute_gt=number-value
The homework asks us to filter for guest age in the right path, using equal to, less than, less than or equal to, greater than, and greater than or equal to. To solve this, I would use the GET method with the guests path and the appropriate ending, like:
GET /guests?age=40
GET /guests?age_gt=40
————————————————————————
Understanding the format and syntax of REST APIs will be very useful for the Software Development Capstone next semester. I understand parameters, how to create schemas, how to reference the schemas and error codes, which are all extremely useful for future projects and in a job setting. As we continue to learn how to use REST APIs and expand our knowledge, I feel comfortable adding REST API design and implementation into my skillset.
From the blog CS@Worcester – ALIDA NORDQUIST by alidanordquist and used with permission of the author. All other rights reserved by the author.


