Coder Social home page Coder Social logo

programming_languages_api's Introduction

Example REST API using Python and Flask

This is a simple example of a REST API built with Python and Flask. The API provides endpoints to perform CRUD (Create, Read, Update, Delete) operations on programming languages.

Requirements

  • Python 3.x
  • Flask (Install using pip install Flask)

Getting Started

  1. Clone the repository:
git clone <repository_url>
cd <repository_name>
  1. Install Flask:
pip install Flask
  1. Run the Flask app:
python app.py

The server should start running on http://127.0.0.1:5000/.

Endpoints

List all programming languages

  • URL: /programming_languages
  • Method: GET
  • Description: Retrieve a list of all programming languages.

Create a programming language

  • URL: /programming_languages
  • Method: POST
  • Description: Create a new programming language.

Get a programming language

  • URL: /programming_languages/<lang_name>
  • Method: GET
  • Description: Retrieve information about a specific programming language.

Update a programming language

  • URL: /programming_languages/<lang_name>
  • Method: PUT
  • Description: Update information for a specific programming language.

Delete a programming language

  • URL: /programming_languages/<lang_name>
  • Method: DELETE
  • Description: Delete a specific programming language.

Request and Response Format

The API accepts JSON data for POST and PUT requests. The response will also be in JSON format.

Sample Request (POST/PUT)

{
  "name": "Python",
  "year_invented": 1991,
  "creator": "Guido van Rossum"
}

Sample Response (GET)

{
  "name": "Python",
  "year_invented": 1991,
  "creator": "Guido van Rossum"
}

Sample Response (GET all)

[
  {
    "name": "Python",
    "year_invented": 1991,
    "creator": "Guido van Rossum"
  },
  {
    "name": "JavaScript",
    "year_invented": 1995,
    "creator": "Brendan Eich"
  },
  ...
]

Sample Response (DELETE)

{
  "message": "Programming language deleted successfully."
}

Error Handling

In case of errors, the API will return appropriate HTTP status codes and error messages in the response.

Sample Usage

Here are some sample cURL commands to interact with the API:

Create a programming language

curl -X POST -H "Content-Type: application/json" -d '{"name":"Java", "year_invented": 1995, "creator": "James Gosling"}' http://127.0.0.1:5000/programming_languages

Get a programming language

curl http://127.0.0.1:5000/programming_languages/Java

Update a programming language

curl -X PUT -H "Content-Type: application/json" -d '{"year_invented": 1996}' http://127.0.0.1:5000/programming_languages/Java

Delete a programming language

curl -X DELETE http://127.0.0.1:5000/programming_languages/Java

License

This project is licensed under the MIT License. Feel free to modify and use it for your own projects.


Please note that this is a basic example for learning purposes and not intended for production use. In a real-world scenario, you would need to add proper error handling, input validation, authentication, and database integration to ensure security and reliability.

programming_languages_api's People

Contributors

pedrovsn 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.