Coder Social home page Coder Social logo

api's Introduction

API

Open in GitHub Codespaces

The repository contains:

  • Distributed code from eCentennial: server.js used to build an API server.
  • /.devcontainer: Configuration file used by Codespaces to determine operating system.
  • /.vscode: Configuration file used by Codespaces to configure Visual Studio Code settings.
  • package.json and yarn.lock: Defines the application information for Node.js, dependent packages, and the versions needed for each.

RESTful API

This is a simple Express application that manages a list of items. It supports basic CRUD operations through a RESTful API:

  • Retrieve all items
  • Retrieve a items by ID
  • Add a new item
  • Edit an existing item by ID
  • Delete a item by ID

Getting Started

Select Open in GitHub Codespaces and then Create codespace. GitHub will prepare the development environment.

Install Packages

Install the necessary dependencies.

yarn

Start the Server

After installing the packages, start the server:

yarn start

Test the REST API

Testing the API with Thunder Client

  1. Open Thunder Client:

    • Open Thunder Client readily installed in Codespaces by clicking on its icon on the sidebar.
  2. Create a New Request:

    • In Thunder Client, click on the New Request button to start setting up the API request.
    • Enter the API endpoint URL in the URL field: http://localhost:8080/api/items.
    • Select the HTTP method POST from the dropdown next to the URL field.
  3. Set Up Request Body:

    • Click on the "Body" tab, choose and enter the JSON data:
    {
      "sportName": "Swimming"
    }
  4. Send the Request:

    • Click the "Send" button to execute the request. Thunder Client will display the response from the API, including status code, response time, and the body.

Endpoints

Get all items

  • URL: /api/items

  • Method: GET

  • Response:

    [
      "Soccer",
      "Handball",
      "Volleyball",
      "Cricket",
      "Swimming"
    ]

Get an item by ID

  • URL: /api/items/:itemId

  • Method: GET

  • URL Params:

    • itemId - ID of the sport
  • Response:

    {
      "sportName": "Volleyball"
    }

Add a new item

  • URL: /api/items

  • Method: POST

  • Body:

    {
      "sportName": "Basketball"
    }
  • Response:

    {
      "message": "Added Basketball as item identifier 5"
    }

Edit an item by ID

  • URL: /api/items/:id

  • Method: PUT

  • URL Params:

    • id - ID of the sport
  • Body:

    {
      "sportName": "Rugby"
    }
  • Response:

    {
      "message": "Updated item with identifier: 0 to Rugby"
    }

Delete an item by ID

  • URL: /api/items/:id

  • Method: DELETE

  • URL Params:

    • id - ID of the sport
  • Response:

    {
      "message": "Deleted sport: Volleyball"
    }

api's People

Contributors

ttran375 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.