Overview



Introduction

Open-Api offers a Rest-API for members of codingwithmitch.com.

The API is designed to provide URL endpoints for some of the courses.

Here are the courses that use this API:

  1. REST API Token Authentication for Mobile Apps
        Kotlin, MVI architecture, Repository pattern, Dagger2, SQLite (Room), Coroutines.


Want to learn how to build a website like open-api.xyz? Here are the courses (they're free):

  1. Building a Website with Django (Python)
  2. Buiding a REST API (Django Rest-framework)


Using the REST API at open-api.xyz:

You'll notice all the requests below require an authentication token. That's how users are authenticated from the mobile app. To validate your authentication tokens:

1. You must have a paid account on codingwithmitch.com

2. Your codingwithmitch.com email must be the same as your open-api.xyz email


Your open-api.xyz account is synced with your codingwithmitch.com account. If you satisfy the two criteria above, your authentication token will be valid.

Enroll to become a codingwithmitch member here:

Enroll



How to Obtain an Authentication Token:

See the section below: Obtaining an Authentication Token



Documentation



Obtaining an Authentication Token

Request: POST

Url:

https://open-api.xyz/api/account/login

Params:

username (Enter your login email)

password (Your password)

No that's not a typo above. The param is username but you use your email.


Success Response:

{
    "response": "Successfully authenticated.",
    "pk": 1,
    "email": "mitch@tabian.ca",
    "token": "27a46967801960de8734f65ba13b124aaea96ad9"
}

Creating a Blog Post

Request: POST

Headers:

Authorization: Token <token>

Url:

https://open-api.xyz/api/blog/create

Params:

title (text)

body (text)

image (file)


Success Response:

{
    "title": "New Title!",
    "body": "this is new body \ncool.\nstuff.",
    "image": "/media/blog/1/New_Title-REST_API_Retrofit2_MVVM_Course_SUMMARY.png",
    "date_updated": "2019-07-09T15:19:33.095626Z",
    "username": "mitch"
}

Viewing a Specific Blog Post

Request: GET

Headers:

Authorization: Token <token>

Url:

https://open-api.xyz/api/blog/<slug>/

Success Response:

{
    "title": "I'm switching to Kotlin",
    "body": "Kotlin fdskgfdg dfgdfg dgdfgd fgdf\nfdg dfg dfgd",
    "image": "/media/blog/1/Im_switching_to_Kotlin-Im_switching_to_Kotlin_eXPxce7.png",
    "date_updated": "2019-07-09T16:02:19.170321Z",
    "username": "mitch"
}

Updating a Specific Blog Post

Request: PUT

Headers:

Authorization: Token <token>

Url:

https://open-api.xyz/api/blog/<slug>/update

Success Response:

{
    "response": "updated"
}

Deleting a Specific Blog Post

Request: DELETE

Headers:

Authorization: Token <token>

Url:

https://open-api.xyz/api/blog/<slug>/delete

Success Response:

{
    "response": "deleted"
}

List Blog Posts (Pagination, Search and Ordering)

Request: GET

Headers:

Authorization: Token <token>

Url:

https://open-api.xyz/api/blog/list/?search=<query>&ordering=-date_updated&page=1

Params:

query (this will search the title and body of blog posts for a match)

ordering (Can use: title, body, username or date_updated)

page (10 results will be shown per page.)


Success Response:

{
    "count": <num_results>,
    "next": null,
    "previous": null,
    "results": [
        {
            "title": "gfhhfghfgh",
            "body": "fghgfhfghf",
            "image": "http://open-api.xyz/media/blog/1/gfhhfghfgh-1.png",
            "date_updated": "2019-07-05T21:43:56.452234Z",
            "username": "mitch"
        },
        ...
}