kirstenopstad / parks

National & State Parks API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parks Lookup API

An API for state and national parks

By Kirsten Opstad


Table of Contents


Technologies Used

  • C#
  • .Net 6
  • ASP.Net Core 6 MVC
  • EF Core 6
  • SQL
  • MySQL
  • LINQ
  • Swagger

Description

A student project demonstrating knowledge of building RESTful APIs. This is an API is a Parks Lookup: an API for state and national parks. The API will list state and national parks.


Objectives

Goals

  1. Meet MVP
  2. [Stretch] Add functionality to call on NPS API to seed db
  3. [Stretch] Add front end MVC app to consume API
  4. [Stretch] Add additional endpoint

MVP (Minimum Viable Product)

  • ✅ Application includes CRUD functionality and successfully returns responses to API calls.
  • ✅ README thoroughly describes all endpoints along with parameters that can be used.
  • ✅ Application includes a best effort at implementing at least one of the further exploration objectives: authentication, versioning, pagination, or CORS.
  • ✅ README includes specific documentation on further exploration: what it is and how to use it.
  • ✅ Build files and sensitive information are included in .gitignore file and is not to be tracked by * Git, and includes instructions on how to create the appsettings.json and set up the project.
  • Project is in a polished, portfolio-quality state.
  • The prompt’s required functionality and baseline project requirements are in place by the deadline.

Strech Goals (Further Exploration)

  1. Add a front end MVC application that consumes your API.
  2. Add a RANDOM endpoint that randomly returns a park/business/animal.
  3. Add a second custom endpoint that accepts parameters. Example: a SEARCH route that allows users to search by specific park names.

Project Outline

Database Schema

Image of database schema


Setup Installation Requirements

Open project

  1. Navigate to the ParksApi directory.
  2. Create a file named appsettings.json with the following code. Be sure to update the Default Connection to your MySQL credentials.
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Port=3306;database=Api;uid=[YOUR-USERNAME-HERE];pwd=[YOUR-PASSWORD-HERE];"
  }
}
  1. Install dependencies within the ParksApi directory
$ dotnet restore
  1. To build & run program in development mode
$ dotnet run
  1. To build & run program in production mode
dotnet run --launch-profile "production"

API Documentation

Endpoints

 GET http://localhost:5000/api/v2/v2/parks
 GET http://localhost:5000/api/v2/parks/{id}
 POST http://localhost:5000/api/v2/parks
 PUT http://localhost:5000/api/v2/parks/{id}
 DELETE http://localhost:5000/api/v2/parks/{id}

Notes:

  • The {id} value in the URL is a variable and should be replaced with the id number of the park the user wants to PUT or DELETE
  • GET http://localhost:5000/api/v2/parks Returns a collection of parks
  • GET http://localhost:5000/api/v2/parks/{id} Returns a single park

Queries

For GET http://localhost:5000/api/v2/parks

Parameter Type Required Description
parkType int Not Required Returns parks with matching parkType value (parkType=1 for National, parkType=2 for State)
State string Not Required Returns parks with matching state value
City string Not Required Returns parks with matching Y value

Example Queries

The following query will return all National parks, indicated by the parkType value of 1:

GET http://localhost:5000/api/v2/parks?parkType=1

The following query will return all State parks, indicated by the parkType value of 2:

GET http://localhost:5000/api/v2/parks?parkType=2

The following query will return all parks within a given state, indicated by the state value of "CA":

GET http://localhost:5000/api/v2/parks?state=ca

The following query will return all parks with the city value of "Big Sur":

GET http://localhost:5000/api/v2/parks?city=big sur

It's possible to include multiple query strings by separating them with an &:

GET http://localhost:5000/api/v2/reviews?parkType=1&state=ca

Endpoints that require body input

POST Requests require a body in JSON format that includes all fields.

Example:

POST http://localhost:5000/api/v2/parks

    {
        "name": "Joshua Tree",
        "state": "CA",
        "city": "Joshua Tree National Park",
        "parkTypeId": 1
    }

Note: that the value for "parkTypeId" MUST be an int. A value of 1 indicates National Park a value of 2 indicates a State Park.

PUT Requests require a body in JSON format that includes all fields.

Example:

PUT http://localhost:5000/api/v2/parks/{id}

    {
        "parkId": 7, 
        "name": "Toshua Tree",
        "state": "MA",
        "city": "Toshua Tree National Park",
        "parkTypeId": 1
    }

Note: that the value for "parkTypeId" MUST be an int. A value of 1 indicates National Park a value of 2 indicates a State Park.

Versions

There are two versions available of the ParksApi. Version 2.0 is the most recent. To revert back to version 1.0, simply replace v2 in the endpoint with v1.

For example:

Version 2.0
GET http://localhost:5000/api/v2/parks

Version 1.0
GET http://localhost:5000/api/v1/parks

Known Bugs

  • No known bugs. If you find one, please email me at kirsten.opstad@gmail.com with the subject [Repo Name] Bug and include:
    • BUG: A brief description of the bug
    • FIX: Suggestion for solution (if you have one!)
    • If you'd like to be credited, please also include your github user profile link

License

MIT License

Copyright (c) 2023 Kirsten Opstad

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

National & State Parks API


Languages

Language:C# 100.0%